Revision 87cd03a1
Added by Patrick Plitzner over 8 years ago
- added findOccurrences() and countOccurrences() to service layer
- added configurator for these methods
- optimized retrieval with HQL query
- made use of service method in DerivateSearchView
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java | ||
---|---|---|
1032 | 1032 |
return defaultService.getMostSignificantIdentifier(derivedUnit); |
1033 | 1033 |
} |
1034 | 1034 |
|
1035 |
/* (non-Javadoc) |
|
1036 |
* @see eu.etaxonomy.cdm.api.service.IOccurrenceService#countOccurrences(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator) |
|
1037 |
*/ |
|
1038 |
@Override |
|
1039 |
public int countOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config) { |
|
1040 |
return defaultService.countOccurrences(config); |
|
1041 |
} |
|
1042 |
|
|
1035 | 1043 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java | ||
---|---|---|
36 | 36 |
import eu.etaxonomy.cdm.model.name.NameRelationship; |
37 | 37 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
38 | 38 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
39 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
|
39 | 40 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
40 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
41 | 41 |
import eu.etaxonomy.cdm.model.reference.Reference; |
42 | 42 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
43 | 43 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
... | ... | |
102 | 102 |
return CdmStore.getService(ITaxonService.class).findTaxaAndNamesForEditor(configurator); |
103 | 103 |
} |
104 | 104 |
|
105 |
|
|
106 |
|
|
105 |
|
|
106 |
|
|
107 | 107 |
|
108 | 108 |
/** |
109 | 109 |
* <p>findReferences</p> |
... | ... | |
167 | 167 |
* @param showFieldUnits if <code>true</code> then also FieldUnits are searched |
168 | 168 |
* @return |
169 | 169 |
*/ |
170 |
public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator configurator, boolean showFieldUnits){ |
|
171 |
if(! showFieldUnits){ |
|
172 |
configurator.setClazz(DerivedUnit.class); |
|
170 |
public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> configurator, boolean showFieldUnits){ |
|
171 |
if(configurator.getClazz()==null){ |
|
172 |
if(showFieldUnits){ |
|
173 |
configurator.setClazz(SpecimenOrObservationBase.class); |
|
174 |
} |
|
175 |
else{ |
|
176 |
configurator.setClazz(DerivedUnit.class); |
|
177 |
} |
|
178 |
} |
|
179 |
if(configurator.getClazz().equals(SpecimenOrObservationBase.class)){ |
|
180 |
//get FieldUnits + DerivedUnits |
|
181 |
List<SpecimenOrObservationBase> records = new ArrayList<SpecimenOrObservationBase>(); |
|
182 |
configurator.setClazz(DerivedUnit.class); |
|
183 |
int derivedUnitCount = CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator); |
|
184 |
configurator.setClazz(FieldUnit.class); |
|
185 |
int fieldUnitCount = CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator); |
|
186 |
|
|
187 |
if(checkLargeResult(derivedUnitCount+fieldUnitCount)){ |
|
188 |
configurator.setClazz(DerivedUnit.class); |
|
189 |
records.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords()); |
|
190 |
configurator.setClazz(FieldUnit.class); |
|
191 |
records.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords()); |
|
192 |
} |
|
193 |
return records; |
|
194 |
|
|
173 | 195 |
} |
174 |
if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countByTitle(configurator))){
|
|
196 |
if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
|
|
175 | 197 |
return CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords(); |
176 | 198 |
} |
177 | 199 |
return NO_RESULTS; |
178 | 200 |
} |
179 | 201 |
|
180 |
/** |
|
181 |
* Searches for {@link SpecimenOrObservationBase} with the parameters specified in the {@link IIdentifiableEntityServiceConfigurator} |
|
182 |
* which match the given {@link SpecimenOrObservationType} |
|
183 |
* @param configurator the configurator to use for the search |
|
184 |
* @param type the type/record basis the specimens must have |
|
185 |
* @return a list of the SpecimenOrObservationBases matching the search parameters found |
|
186 |
|
|
187 |
* @deprecated method needs to be optimized with a direct SQL query instead of iterating over all specimens |
|
188 |
*/ |
|
189 |
@Deprecated |
|
190 |
//TODO: method needs to be optimized with a direct SQL query instead of iterating over all specimens |
|
191 |
public List<SpecimenOrObservationBase> findOccurrencesByType(IIdentifiableEntityServiceConfigurator configurator, SpecimenOrObservationType type){ |
|
192 |
List<SpecimenOrObservationBase> filteredOccurrences = new ArrayList<SpecimenOrObservationBase>(); |
|
193 |
List<SpecimenOrObservationBase> occurrences = findOccurrences(configurator, true); |
|
194 |
if(type!=null){ |
|
195 |
for(SpecimenOrObservationBase occurrence:occurrences){ |
|
196 |
if(occurrence.getRecordBasis().equals(type) |
|
197 |
|| occurrence.getRecordBasis().isKindOf(type) |
|
198 |
|| type == SpecimenOrObservationType.Unknown){ |
|
199 |
filteredOccurrences.add(occurrence); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
else{ |
|
204 |
filteredOccurrences = occurrences; |
|
205 |
} |
|
206 |
return filteredOccurrences; |
|
207 |
} |
|
208 |
|
|
209 | 202 |
public List<User> findUsers(IIdentifiableEntityServiceConfigurator configurator){ |
210 | 203 |
String userNameSearchString = sqlizeTitleSearchString(configurator); |
211 | 204 |
// TODO why are users not identifiable entities? |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateSearchCompositeController.java | ||
---|---|---|
28 | 28 |
import org.eclipse.ui.handlers.IHandlerService; |
29 | 29 |
|
30 | 30 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
31 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy; |
|
32 | 31 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
33 |
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator; |
|
34 |
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl; |
|
32 |
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator; |
|
35 | 33 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
36 | 34 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
37 | 35 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
38 | 36 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
39 | 37 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
40 | 38 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
39 |
import eu.etaxonomy.taxeditor.store.SearchManager; |
|
41 | 40 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory; |
42 | 41 |
import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController; |
43 | 42 |
|
... | ... | |
50 | 49 |
public class DerivateSearchCompositeController implements Listener{ |
51 | 50 |
|
52 | 51 |
private final DerivateSearchComposite derivateSearchComposite; |
53 |
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>> configurator; |
|
54 |
private EnumTermComboController<SpecimenOrObservationType> enumTermComboController; |
|
52 |
private EnumTermComboController<SpecimenOrObservationType> comboSpecimenTypeController; |
|
55 | 53 |
private final DerivateSearchView derivateSearchView; |
56 | 54 |
private DerivateLabelProvider labelProvider; |
57 | 55 |
private Taxon selectedTaxon; |
... | ... | |
68 | 66 |
|
69 | 67 |
private void init(){ |
70 | 68 |
//derivate type combo |
71 |
enumTermComboController = new EnumTermComboController<SpecimenOrObservationType>(derivateSearchComposite.getComboDerivateType(), null, null, SpecimenOrObservationType.class, 0);
|
|
72 |
enumTermComboController.setSelection(SpecimenOrObservationType.Unknown);
|
|
69 |
comboSpecimenTypeController = new EnumTermComboController<SpecimenOrObservationType>(derivateSearchComposite.getComboDerivateType(), null, null, SpecimenOrObservationType.class, 0);
|
|
70 |
comboSpecimenTypeController.setSelection(SpecimenOrObservationType.Unknown);
|
|
73 | 71 |
|
74 | 72 |
//add listeners |
75 | 73 |
derivateSearchComposite.getSearchField().addListener(SWT.KeyDown, this); |
... | ... | |
103 | 101 |
|
104 | 102 |
} |
105 | 103 |
}); |
106 |
configurator = new IdentifiableServiceConfiguratorImpl<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>>(); |
|
107 | 104 |
|
108 | 105 |
} |
109 | 106 |
|
... | ... | |
112 | 109 |
derivateSearchView.setFocus(); //rebind the conversation |
113 | 110 |
} |
114 | 111 |
|
112 |
String queryString = derivateSearchComposite.getSearchField().getText(); |
|
113 |
SpecimenOrObservationType specimenType = comboSpecimenTypeController.getSelection(); |
|
115 | 114 |
|
116 |
List<SpecimenOrObservationBase<?>> filteredByAssociatedTaxon = null; |
|
117 |
//filter by taxon |
|
118 |
if(selectedTaxon!=null){ |
|
119 |
filteredByAssociatedTaxon = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(null, null, selectedTaxon, null, null, null, null, null); |
|
120 |
} |
|
115 |
FindOccurrencesConfigurator config = new FindOccurrencesConfigurator(); |
|
116 |
config.setAssociatedTaxonUuid(selectedTaxon!=null?selectedTaxon.getUuid():null); |
|
117 |
config.setSpecimenType(specimenType==SpecimenOrObservationType.Unknown?null:specimenType);//unknown := all types |
|
118 |
config.setTitleSearchString(queryString); |
|
121 | 119 |
|
122 |
//filter by specimen type |
|
123 |
configurator.setTitleSearchString(derivateSearchComposite.getSearchField().getText()); |
|
124 |
SpecimenOrObservationType type = enumTermComboController.getSelection(); |
|
125 |
List<SpecimenOrObservationBase> filteredByType = new ArrayList<SpecimenOrObservationBase>(); |
|
126 |
if(filteredByAssociatedTaxon!=null){ |
|
127 |
for (SpecimenOrObservationBase specimenOrObservationBase : filteredByAssociatedTaxon) { |
|
128 |
if(type.equals(SpecimenOrObservationType.Unknown) || specimenOrObservationBase.getRecordBasis().equals(type)){ |
|
129 |
filteredByType.add(specimenOrObservationBase); |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
else{ |
|
134 |
filteredByType = CdmStore.getSearchManager().findOccurrencesByType(configurator, type); |
|
135 |
} |
|
120 |
SearchManager searchManager = new SearchManager(); |
|
121 |
List<SpecimenOrObservationBase> occurrences = searchManager.findOccurrences(config); |
|
136 | 122 |
|
137 | 123 |
//filter out assigned specimens |
138 | 124 |
if(derivateSearchComposite.getBtnFilterUndeterminedSpecimen().getSelection()){ |
139 | 125 |
List<SpecimenOrObservationBase> specimensWithNoDetermination = new ArrayList<SpecimenOrObservationBase>(); |
140 |
for(SpecimenOrObservationBase<?> result:filteredByType){
|
|
126 |
for(SpecimenOrObservationBase<?> result:occurrences){
|
|
141 | 127 |
if(CdmStore.getService(IOccurrenceService.class).countDeterminations(result, null)==0){ |
142 | 128 |
specimensWithNoDetermination.add(result); |
143 | 129 |
} |
144 | 130 |
} |
145 |
filteredByType = specimensWithNoDetermination;
|
|
131 |
occurrences = specimensWithNoDetermination;
|
|
146 | 132 |
} |
147 |
derivateSearchComposite.getResultViewer().setInput(filteredByType);
|
|
133 |
derivateSearchComposite.getResultViewer().setInput(occurrences);
|
|
148 | 134 |
} |
149 | 135 |
|
150 | 136 |
/* (non-Javadoc) |
... | ... | |
185 | 171 |
public void reset(){ |
186 | 172 |
derivateSearchComposite.getResultViewer().setInput(null); |
187 | 173 |
derivateSearchComposite.getSearchField().setText(""); |
188 |
enumTermComboController.setSelection(SpecimenOrObservationType.Unknown);
|
|
174 |
comboSpecimenTypeController.setSelection(SpecimenOrObservationType.Unknown);
|
|
189 | 175 |
derivateSearchComposite.getComboDerivateType().deselectAll(); |
190 | 176 |
selectedTaxon = null; |
191 | 177 |
} |
Also available in: Unified diff