import eu.etaxonomy.cdm.model.common.User;
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.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
public List<TaxonNameBase> findNames(IIdentifiableEntityServiceConfigurator configurator){
if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
List<TaxonNameBase> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
- TaxonNameBase uuidSearchResult = addUuidSearchResults(configurator, INameService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, INameService.class);
return records;
}
return NO_RESULTS;
public List<Reference> findReferences(IIdentifiableEntityServiceConfigurator configurator){
if(checkLargeResult(CdmStore.getService(IReferenceService.class).countByTitle(configurator))){
List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
- Reference uuidSearchResult = addUuidSearchResults(configurator, IReferenceService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, IReferenceService.class);
return records;
}
return NO_RESULTS;
public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
- AgentBase uuidSearchResult = addUuidSearchResults(configurator, IAgentService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, IAgentService.class);
return records;
}
return NO_RESULTS;
/**
* Check search string if it is a {@link UUID} and, if <code>true</code>, search for the corresponding entity.
+ * @param records the list to which the search results are added
* @param configurator the configurator holding the search string
* @param service the service to use for searching
*/
- private <T extends ICdmBase> T addUuidSearchResults(IIdentifiableEntityServiceConfigurator configurator, Class<? extends IService<T>> service) {
+ private <T extends ICdmBase> void addUuidSearchResults(List<T> records, IIdentifiableEntityServiceConfigurator configurator, Class<? extends IService<T>> service) {
String titleSearchString = configurator.getTitleSearchString();
try {
UUID uuid = UUID.fromString(titleSearchString);
- return CdmStore.getService(service).find(uuid);
+ T foundRecord = CdmStore.getService(service).find(uuid);
+ if(foundRecord!=null){
+ records.add(foundRecord);
+ }
} catch (IllegalArgumentException e) {
//search string was no UUID
}
- return null;
}
@SuppressWarnings("unchecked")
*/
public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> configurator, boolean showFieldUnits){
List<SpecimenOrObservationBase> records = new ArrayList<SpecimenOrObservationBase>();
- if(configurator.getClazz()==null){
- if(showFieldUnits){
- configurator.setClazz(SpecimenOrObservationBase.class);
- }
- else{
- configurator.setClazz(DerivedUnit.class);
- }
+ 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"
+ });
+
+ List<String> occurrencePropertyPaths = new ArrayList<String>();
+ occurrencePropertyPaths.addAll(BASE_OCCURRENCE_INIT_STRATEGY);
+ for(String propertyPath:BASE_OCCURRENCE_INIT_STRATEGY) {
+ occurrencePropertyPaths.add("derivationEvents.derivatives." + propertyPath);
}
- if(configurator.getClazz().equals(SpecimenOrObservationBase.class)){
- //get FieldUnits + DerivedUnits
- configurator.setClazz(DerivedUnit.class);
- int derivedUnitCount = CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator);
- configurator.setClazz(FieldUnit.class);
- int fieldUnitCount = CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator);
-
- if(checkLargeResult(derivedUnitCount+fieldUnitCount)){
- configurator.setClazz(DerivedUnit.class);
- records.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords());
- configurator.setClazz(FieldUnit.class);
- records.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords());
- }
+ configurator.setPropertyPaths(occurrencePropertyPaths);
- }
- else if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
+ if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
}
- SpecimenOrObservationBase uuidSearchResult = addUuidSearchResults(configurator, IOccurrenceService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, IOccurrenceService.class);
return records;
}
String userNameSearchString = sqlizeTitleSearchString(configurator);
// TODO why are users not identifiable entities?
List<User> records = CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
- User uuidSearchResult = addUuidSearchResults(configurator, IUserService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, IUserService.class);
return records;
}
String groupNameSearchString = sqlizeTitleSearchString(configurator);
// TODO why are groups not identifiable entities?
List<Group> records = CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
- Group uuidSearchResult = addUuidSearchResults(configurator, IGroupService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, IGroupService.class);
return records;
}
public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {
if(checkLargeResult(CdmStore.getService(ITaxonService.class).countByTitle(configurator))){
List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
- TaxonBase uuidSearchResult = addUuidSearchResults(configurator, ITaxonService.class);
- if(uuidSearchResult!=null){
- records.add(uuidSearchResult);
- }
+ addUuidSearchResults(records, configurator, ITaxonService.class);
return records;
}
return NO_RESULTS;