X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/f2e686b92dd60502e7f0c777de7ca75c19d93f62..a500a93f8b207d9620b61ca2605ab43b4b909966:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java?ds=sidebyside
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
index 2d514fa8a..99eb03129 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
@@ -1,9 +1,9 @@
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
@@ -34,8 +34,9 @@ import eu.etaxonomy.cdm.model.common.User;
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
import eu.etaxonomy.cdm.model.name.NameRelationship;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
@@ -47,16 +48,16 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
* @version 1.0
*/
public class SearchManager {
-
+
public static final List NO_RESULTS = Arrays.asList(new Object[]{});
-
+
public static final String WILDCARD = "*";
-
+
public static int NO_COUNT = -1;
-
+
// TODO make this configurable via preferences
- private static final int MAX_RESULTS_BEFORE_WARNING = 500;
-
+ private static final int MAX_RESULTS_BEFORE_WARNING = 500;
+
/**
*
findNames
*
@@ -69,25 +70,25 @@ public class SearchManager {
}
return NO_RESULTS;
}
-
+
public List findNameRelationships(
IIdentifiableEntityServiceConfigurator configurator) {
if(true){
return NO_RESULTS;
}
-
- List relationships = new ArrayList();
+
+ List relationships = new ArrayList();
List all = CdmStore.getService(INameService.class).getAllRelationships(0, 0);
-
+
for (RelationshipBase relationship : all){
if(relationship instanceof NameRelationship){
relationships.add((NameRelationship) relationship);
}
}
-
-
+
+
return relationships;
-
+
}
/**
@@ -99,8 +100,8 @@ public class SearchManager {
public List> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator){
return CdmStore.getService(ITaxonService.class).findTaxaAndNamesForEditor(configurator);
}
-
-
+
+
/**
* findReferences
*
@@ -113,8 +114,8 @@ public class SearchManager {
}
return NO_RESULTS;
}
-
-
+
+
/**
* findAgents
*
@@ -138,57 +139,100 @@ public class SearchManager {
configurator.setClazz(TeamOrPersonBase.class);
return findAgents(configurator);
}
-
-
+
/**
- * findOccurrences
+ * Searches for {@link SpecimenOrObservationBase} with the parameters specified in the
+ * {@link IIdentifiableEntityServiceConfigurator}
+ *
+ * Note: FieldUnits are omitted by default. See {@link #findOccurrences(IIdentifiableEntityServiceConfigurator, boolean)}
*
- * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
- * @return a {@link java.util.List} object.
+ * @param configurator the configurator to use for the search
+ * @return a list of the SpecimenOrObservationBases matching the search parameters found
*/
public List findOccurrences(IIdentifiableEntityServiceConfigurator configurator){
- // by default we do not show field observations. This may be configured via preferences
- boolean showFieldObservations = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.BULK_EDITOR_OCCURRENCE_SHOW_FIELD_OBSERVATIONS);
- if(! showFieldObservations){
- configurator.setClazz(DerivedUnitBase.class);
+ // by default we do not show field units. This may be configured via preferences
+ return findOccurrences(configurator, PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.BULK_EDITOR_OCCURRENCE_SHOW_FIELD_UNITS));
+ }
+
+
+ /**
+ * Searches for {@link SpecimenOrObservationBase} with the parameters specified in the
+ * {@link IIdentifiableEntityServiceConfigurator}
+ *
+ * @param configurator the configurator to use for the search
+ * @return a list of the SpecimenOrObservationBases found
+ * @param showFieldUnits if true
then also FieldUnits are searched
+ * @return
+ */
+ public List findOccurrences(IIdentifiableEntityServiceConfigurator configurator, boolean showFieldUnits){
+ if(! showFieldUnits){
+ configurator.setClazz(DerivedUnit.class);
}
if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countByTitle(configurator))){
return CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
}
return NO_RESULTS;
}
-
-
+
+ /**
+ * Searches for {@link SpecimenOrObservationBase} with the parameters specified in the {@link IIdentifiableEntityServiceConfigurator}
+ * which match the given {@link SpecimenOrObservationType}
+ * @param configurator the configurator to use for the search
+ * @param type the type/record basis the specimens must have
+ * @return a list of the SpecimenOrObservationBases matching the search parameters found
+
+ * @deprecated method needs to be optimized with a direct SQL query instead of iterating over all specimens
+ */
+ @Deprecated
+ //TODO: method needs to be optimized with a direct SQL query instead of iterating over all specimens
+ public List findOccurrencesByType(IIdentifiableEntityServiceConfigurator configurator, SpecimenOrObservationType type){
+ List filteredOccurrences = new ArrayList();
+ List occurrences = findOccurrences(configurator, true);
+ if(type!=null){
+ for(SpecimenOrObservationBase occurrence:occurrences){
+ if(occurrence.getRecordBasis().equals(type)
+ || occurrence.getRecordBasis().isKindOf(type)
+ || type == SpecimenOrObservationType.Unknown){
+ filteredOccurrences.add(occurrence);
+ }
+ }
+ }
+ else{
+ filteredOccurrences = occurrences;
+ }
+ return filteredOccurrences;
+ }
+
public List findUsers(IIdentifiableEntityServiceConfigurator configurator){
String userNameSearchString = sqlizeTitleSearchString(configurator);
// TODO why are users not identifiable entities?
return CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
}
-
-
+
+
public List findGroups(IIdentifiableEntityServiceConfigurator configurator){
String groupNameSearchString = sqlizeTitleSearchString(configurator);
// TODO why are groups not identifiable entities?
return CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
}
-
-
+
+
/**
* @param count
* @return
*/
private boolean checkLargeResult(int count) {
if(count > MAX_RESULTS_BEFORE_WARNING){
- return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Large result expected",
+ return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Large result expected",
String.format("The current search will return %s objects. This will " +
"take a long time and/or might render the editor unusable. Please consider refining your search.", count));
}else{
return true;
- }
+ }
}
-
+
/**
- *
+ *
* @param configurator
* @return
*/