Project

General

Profile

« Previous | Next » 

Revision a9108118

Added by Patrick Plitzner over 8 years ago

Optimize Code #5103

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
65 65
	public List<TaxonNameBase> findNames(IIdentifiableEntityServiceConfigurator configurator){
66 66
		if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
67 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
            }
68
			addUuidSearchResults(records, configurator, INameService.class);
72 69
            return records;
73 70
		}
74 71
		return NO_RESULTS;
......
99 96
	public List<Reference> findReferences(IIdentifiableEntityServiceConfigurator configurator){
100 97
		if(checkLargeResult(CdmStore.getService(IReferenceService.class).countByTitle(configurator))){
101 98
			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
            }
99
			addUuidSearchResults(records, configurator, IReferenceService.class);
106 100
            return records;
107 101
		}
108 102
		return NO_RESULTS;
......
111 105
	public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
112 106
		if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
113 107
			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
			}
108
			addUuidSearchResults(records, configurator, IAgentService.class);
118 109
            return records;
119 110
		}
120 111
		return NO_RESULTS;
......
122 113

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

  
139 130
	@SuppressWarnings("unchecked")
......
194 185
		else if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
195 186
			records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
196 187
		}
197
		SpecimenOrObservationBase uuidSearchResult = addUuidSearchResults(configurator, IOccurrenceService.class);
198
        if(uuidSearchResult!=null){
199
            records.add(uuidSearchResult);
200
        }
188
		addUuidSearchResults(records, configurator, IOccurrenceService.class);
201 189
		return records;
202 190
	}
203 191

  
......
205 193
		String userNameSearchString = sqlizeTitleSearchString(configurator);
206 194
		// TODO why are users not identifiable entities?
207 195
		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
		}
196
		addUuidSearchResults(records, configurator, IUserService.class);
212 197
        return records;
213 198
	}
214 199

  
......
217 202
		String groupNameSearchString = sqlizeTitleSearchString(configurator);
218 203
		// TODO why are groups not identifiable entities?
219 204
		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
		}
205
		addUuidSearchResults(records, configurator, IGroupService.class);
224 206
        return records;
225 207
	}
226 208

  
......
242 224
	public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {
243 225
		if(checkLargeResult(CdmStore.getService(ITaxonService.class).countByTitle(configurator))){
244 226
			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
			}
227
			addUuidSearchResults(records, configurator, ITaxonService.class);
249 228
            return records;
250 229
		}
251 230
		return NO_RESULTS;

Also available in: Unified diff