Project

General

Profile

Revision 0c12e309

ID0c12e309ff3562ad1bac071877ffc6d6ab47ee9b
Parent 4235f40e
Child cd993d95

Added by Andreas Kohlbecker about 2 years ago

ref #7523 exteding CdmFilterablePagingProvider by Restrictions filter

View differences:

src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java
458 458
            institution = instituteMap.get(office);
459 459
        } else {
460 460

  
461
            Pager<AgentBase> pager = repo.getAgentService().findByTitle(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
461
            Pager<AgentBase> pager = repo.getAgentService().findByTitleWithRestrictions(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
462 462
            if(!pager.getRecords().isEmpty()){
463 463
                institution =  (Institution) pager.getRecords().get(0);
464 464
            } else {
src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
20 20
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
21 21
import eu.etaxonomy.cdm.api.service.pager.Pager;
22 22
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
23 24
import eu.etaxonomy.cdm.persistence.query.MatchMode;
24 25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25 26

  
......
49 50

  
50 51
    private List<Criterion> criteria = new ArrayList<>();
51 52

  
53
    private List<Restriction<?>> restrictions = new ArrayList<>();
54

  
52 55

  
53 56
    /**
54 57
     * @return the matchMode
......
116 119
    public List<V> findEntities(int firstRow, String filter) {
117 120

  
118 121
        Integer pageIndex = firstRow / pageSize;
119
        Pager<V> page = (Pager<V>) service.findByTitle(
120
                type,
121
                filter,
122
                matchMode,
123
                criteria,
124
                pageSize,
125
                pageIndex ,
126
                orderHints,
127
                initStrategy
128
              );
122
        Pager<V> page;
123
        if(!restrictions.isEmpty() && criteria.isEmpty()){
124
            page = (Pager<V>) service.findByTitleWithRestrictions(
125
                    type,
126
                    filter,
127
                    matchMode,
128
                    restrictions,
129
                    pageSize,
130
                    pageIndex ,
131
                    orderHints,
132
                    initStrategy
133
                    );
134
        } else if(restrictions.isEmpty() && !criteria.isEmpty()){
135
            page = (Pager<V>) service.findByTitle(
136
                    type,
137
                    filter,
138
                    matchMode,
139
                    criteria,
140
                    pageSize,
141
                    pageIndex ,
142
                    orderHints,
143
                    initStrategy
144
                    );
145
        } else {
146
            // this will never be reaced sind the size() method is always called before.
147
            throw new RuntimeException("Citeria and Restrictions must not be used at the same time");
148
        }
129 149
        if(logger.isTraceEnabled()){
130 150
            logger.trace("findEntities() - page: " + page.getCurrentIndex() + "/" + page.getPagesAvailable() + " totalRecords: " + page.getCount() + "\n" + page.getRecords());
131 151
        }
......
138 158
    @Override
139 159
    public int size(String filter) {
140 160

  
141
        Pager<V> page = (Pager<V>) service.findByTitle(
142
                type,
143
                filter,
144
                matchMode,
145
                criteria,
146
                1,
147
                0,
148
                null,
149
                null
150
              );
161
        Pager<V> page;
162
        if(!restrictions.isEmpty() && criteria.isEmpty()){
163
            page = (Pager<V>) service.findByTitleWithRestrictions(
164
                    type,
165
                    filter,
166
                    matchMode,
167
                    restrictions,
168
                    1,
169
                    0,
170
                    null,
171
                    null
172
                  );
173
        } else if(restrictions.isEmpty() && !criteria.isEmpty()){
174
            page = (Pager<V>) service.findByTitle(
175
                    type,
176
                    filter,
177
                    matchMode,
178
                    criteria,
179
                    1,
180
                    0,
181
                    null,
182
                    null
183
                  );
184
        } else {
185
            throw new RuntimeException("Citeria and Restrictions must not be used at the same time");
186
        }
187

  
151 188
        if(logger.isTraceEnabled()){
152 189
            logger.trace("size() -  count: " + page.getCount().intValue());
153 190
        }
......
190 227
    public List<Criterion> getCriteria() {
191 228
        return criteria;
192 229
    }
230

  
231
    public void addCriterion(Criterion criterion){
232
        criteria.add(criterion);
233
    }
234

  
235
    /**
236
     * The list of restrictions is initially empty.
237
     *
238
     * @return the restrictions
239
     */
240
    public List<Restriction<?>> getRestrictions() {
241
        return restrictions;
242
    }
243

  
244
    public void addRestriction(Restriction<?> restriction){
245
        restrictions.add(restriction);
246
    }
193 247
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)