-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IAgentService;
import eu.etaxonomy.cdm.api.service.IGroupService;
import eu.etaxonomy.cdm.api.service.IMediaService;
import eu.etaxonomy.cdm.model.common.User;
import eu.etaxonomy.cdm.model.media.Media;
import eu.etaxonomy.cdm.model.name.NameRelationship;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
* @author n.hoffmann
* @created Dec 8, 2010
- * @version 1.0
*/
public class SearchManager {
public static final List NO_RESULTS = Arrays.asList(new Object[]{});
- public static final String WILDCARD = "*";
+ public static final String WILDCARD = "*"; //$NON-NLS-1$
public static int NO_COUNT = -1;
+
// TODO make this configurable via preferences
private static final int MAX_RESULTS_BEFORE_WARNING = 500;
- public List<TaxonNameBase> findNames(IIdentifiableEntityServiceConfigurator configurator){
+ public List<TaxonName> findNames(IIdentifiableEntityServiceConfigurator configurator, ConversationHolder conversation){
+
if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
- List<TaxonNameBase> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
+ List<TaxonName> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
addUuidSearchResults(records, configurator, INameService.class);
return records;
}
}
public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
+
if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
addUuidSearchResults(records, configurator, IAgentService.class);
String titleSearchString = configurator.getTitleSearchString();
try {
UUID uuid = UUID.fromString(titleSearchString);
- T foundRecord = CdmStore.getService(service).find(uuid);
+ T foundRecord = (T) CdmStore.getService(service).load(uuid, configurator.getPropertyPaths());
if(foundRecord!=null){
records.add(foundRecord);
}
public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> configurator, boolean showFieldUnits){
List<SpecimenOrObservationBase> records = new ArrayList<SpecimenOrObservationBase>();
final List<String> BASE_OCCURRENCE_INIT_STRATEGY = Arrays.asList(new String[] {
- "collection",
- "descriptions",
- "identifiers",
- "derivationEvents.originals",
- "derivedFrom.originals",
- "gatheringEvent.country.representations",
- "gatheringEvent.collector",
- "gatheringEvent.locality",
- "descriptions.descriptionElements",
- "kindOfUnit",
- "amplificationResults",
- "sequences.singleReadAlignments",
- "mediaSpecimen"
+ "collection", //$NON-NLS-1$
+ "descriptions", //$NON-NLS-1$
+ "identifiers", //$NON-NLS-1$
+ "derivationEvents.originals", //$NON-NLS-1$
+ "derivedFrom.originals", //$NON-NLS-1$
+ "gatheringEvent.country.representations", //$NON-NLS-1$
+ "gatheringEvent.collector", //$NON-NLS-1$
+ "gatheringEvent.locality", //$NON-NLS-1$
+ "descriptions.descriptionElements", //$NON-NLS-1$
+ "kindOfUnit", //$NON-NLS-1$
+ "amplificationResults", //$NON-NLS-1$
+ "sequences.singleReadAlignments", //$NON-NLS-1$
+ "mediaSpecimen" //$NON-NLS-1$
});
- if(configurator.getClazz()==null){
- if(showFieldUnits){
- configurator.setClazz(SpecimenOrObservationBase.class);
- }
- else{
- configurator.setClazz(DerivedUnit.class);
- }
- }
List<String> occurrencePropertyPaths = new ArrayList<String>();
occurrencePropertyPaths.addAll(BASE_OCCURRENCE_INIT_STRATEGY);
for(String propertyPath:BASE_OCCURRENCE_INIT_STRATEGY) {
- occurrencePropertyPaths.add("derivationEvents.derivatives." + propertyPath);
+ occurrencePropertyPaths.add("derivationEvents.derivatives." + propertyPath); //$NON-NLS-1$
}
configurator.setPropertyPaths(occurrencePropertyPaths);
private boolean checkLargeResult(int count, int maxBeforWarning) {
if(count > maxBeforWarning){
- 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));
+ return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.SearchManager_LARGE_RESULT_EXPECTED,
+ String.format(Messages.SearchManager_LONG_SEARCH_WARNING, count));
}else{
return true;
}
}
private String sqlizeTitleSearchString(IIdentifiableEntityServiceConfigurator configurator){
- return configurator.getTitleSearchString().replace(WILDCARD, "%");
+ return configurator.getTitleSearchString().replace(WILDCARD, "%"); //$NON-NLS-1$
}
public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {