Project

General

Profile

« Previous | Next » 

Revision c8938223

Added by Patrick Plitzner over 8 years ago

Support UUID search in bulk editors (#5103)

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
13 13
import java.util.ArrayList;
14 14
import java.util.Arrays;
15 15
import java.util.List;
16
import java.util.UUID;
16 17

  
17 18
import org.eclipse.jface.dialogs.MessageDialog;
18 19
import org.eclipse.swt.widgets.Display;
......
22 23
import eu.etaxonomy.cdm.api.service.INameService;
23 24
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
24 25
import eu.etaxonomy.cdm.api.service.IReferenceService;
26
import eu.etaxonomy.cdm.api.service.IService;
25 27
import eu.etaxonomy.cdm.api.service.ITaxonService;
26 28
import eu.etaxonomy.cdm.api.service.IUserService;
27 29
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
......
29 31
import eu.etaxonomy.cdm.model.agent.AgentBase;
30 32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
31 33
import eu.etaxonomy.cdm.model.common.Group;
34
import eu.etaxonomy.cdm.model.common.ICdmBase;
32 35
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
33 36
import eu.etaxonomy.cdm.model.common.RelationshipBase;
34 37
import eu.etaxonomy.cdm.model.common.User;
......
61 64

  
62 65
	public List<TaxonNameBase> findNames(IIdentifiableEntityServiceConfigurator configurator){
63 66
		if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
64
			return CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
67
			List<TaxonNameBase> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
68
			TaxonNameBase uuidSearchResult = addUuidSearchResults(configurator, INameService.class);
69
            if(uuidSearchResult!=null){
70
                records.add(uuidSearchResult);
71
            }
72
            return records;
65 73
		}
66 74
		return NO_RESULTS;
67 75
	}
......
69 77
	public List<NameRelationship> findNameRelationships(
70 78
			IIdentifiableEntityServiceConfigurator configurator) {
71 79
		if(true){
80
		    //if activated again remember to add uuid search results like in other searches
72 81
			return NO_RESULTS;
73 82
		}
74 83

  
......
89 98

  
90 99
	public List<Reference> findReferences(IIdentifiableEntityServiceConfigurator configurator){
91 100
		if(checkLargeResult(CdmStore.getService(IReferenceService.class).countByTitle(configurator))){
92
			return  CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
101
			List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
102
			Reference uuidSearchResult = addUuidSearchResults(configurator, IReferenceService.class);
103
            if(uuidSearchResult!=null){
104
                records.add(uuidSearchResult);
105
            }
106
            return records;
93 107
		}
94 108
		return NO_RESULTS;
95 109
	}
96 110

  
97 111
	public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
98 112
		if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
99
			return CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
113
			List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
114
			AgentBase uuidSearchResult = addUuidSearchResults(configurator, IAgentService.class);
115
			if(uuidSearchResult!=null){
116
			    records.add(uuidSearchResult);
117
			}
118
            return records;
100 119
		}
101 120
		return NO_RESULTS;
102 121
	}
103 122

  
123
    /**
124
     * Check search string if it is a {@link UUID} and, if <code>true</code>, search for the corresponding entity.
125
     * @param configurator the configurator holding the search string
126
     * @param service the service to use for searching
127
     */
128
    private <T extends ICdmBase> T addUuidSearchResults(IIdentifiableEntityServiceConfigurator configurator, Class<? extends IService<T>> service) {
129
        String titleSearchString = configurator.getTitleSearchString();
130
		try {
131
		    UUID uuid = UUID.fromString(titleSearchString);
132
		    return CdmStore.getService(service).find(uuid);
133
		} catch (IllegalArgumentException e) {
134
		    //search string was no UUID
135
		}
136
		return null;
137
    }
138

  
104 139
	@SuppressWarnings("unchecked")
105 140
	public List<TeamOrPersonBase> findTeamOrPersons(IIdentifiableEntityServiceConfigurator configurator){
106
		configurator.setClazz(TeamOrPersonBase.class);
107
		return (List)findAgents(configurator);
141
	    configurator.setClazz(TeamOrPersonBase.class);
142
	    return (List)findAgents(configurator);
108 143
	}
109 144

  
110 145
	/**
......
132 167
	 * @return
133 168
	 */
134 169
	public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> configurator, boolean showFieldUnits){
170
	    List<SpecimenOrObservationBase> records = new ArrayList<SpecimenOrObservationBase>();
135 171
		if(configurator.getClazz()==null){
136 172
		    if(showFieldUnits){
137 173
		        configurator.setClazz(SpecimenOrObservationBase.class);
......
142 178
		}
143 179
		if(configurator.getClazz().equals(SpecimenOrObservationBase.class)){
144 180
		    //get FieldUnits + DerivedUnits
145
		    List<SpecimenOrObservationBase> records = new ArrayList<SpecimenOrObservationBase>();
146 181
		    configurator.setClazz(DerivedUnit.class);
147 182
		    int derivedUnitCount = CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator);
148 183
		    configurator.setClazz(FieldUnit.class);
......
154 189
		        configurator.setClazz(FieldUnit.class);
155 190
		        records.addAll(CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords());
156 191
		    }
157
		    return records;
158 192

  
159 193
		}
160
		if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
161
			return CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
194
		else if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
195
			records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
162 196
		}
163
		return NO_RESULTS;
197
		SpecimenOrObservationBase uuidSearchResult = addUuidSearchResults(configurator, IOccurrenceService.class);
198
        if(uuidSearchResult!=null){
199
            records.add(uuidSearchResult);
200
        }
201
		return records;
164 202
	}
165 203

  
166 204
	public List<User> findUsers(IIdentifiableEntityServiceConfigurator configurator){
167 205
		String userNameSearchString = sqlizeTitleSearchString(configurator);
168 206
		// TODO why are users not identifiable entities?
169
		return CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
207
		List<User> records = CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
208
		User uuidSearchResult = addUuidSearchResults(configurator, IUserService.class);
209
		if(uuidSearchResult!=null){
210
		    records.add(uuidSearchResult);
211
		}
212
        return records;
170 213
	}
171 214

  
172 215

  
173 216
	public List<Group> findGroups(IIdentifiableEntityServiceConfigurator configurator){
174 217
		String groupNameSearchString = sqlizeTitleSearchString(configurator);
175 218
		// TODO why are groups not identifiable entities?
176
		return CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
219
		List<Group> records = CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
220
		Group uuidSearchResult = addUuidSearchResults(configurator, IGroupService.class);
221
		if(uuidSearchResult!=null){
222
		    records.add(uuidSearchResult);
223
		}
224
        return records;
177 225
	}
178 226

  
179 227

  
......
193 241

  
194 242
	public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {
195 243
		if(checkLargeResult(CdmStore.getService(ITaxonService.class).countByTitle(configurator))){
196
			return CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
244
			List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
245
			TaxonBase uuidSearchResult = addUuidSearchResults(configurator, ITaxonService.class);
246
			if(uuidSearchResult!=null){
247
			    records.add(uuidSearchResult);
248
			}
249
            return records;
197 250
		}
198 251
		return NO_RESULTS;
199 252
	}

Also available in: Unified diff