Project

General

Profile

« Previous | Next » 

Revision 29686

Implemented index client

View differences:

IndexClientFactory.java
1 1
package eu.dnetlib.functionality.index.client;
2 2

  
3
import java.util.List;
3
public interface IndexClientFactory {
4 4

  
5
import javax.annotation.Resource;
5
	String getBackendId();
6 6

  
7
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
8
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
9
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
10
import eu.dnetlib.enabling.tools.ServiceLocator;
7
	IndexClient getClient(String format, String layout, String interpretation) throws IndexClientException;
11 8

  
12
public class IndexClientFactory {
13
	
14
	@Resource
15
	private List<IndexClient> indexClients;
16
		
17
	@Resource(name="lookupLocator")
18
	private ServiceLocator<ISLookUpService> lookupLocator;
19
	
20
	
21
	public IndexClient getClient(final String format, final String layout, final String interpretation) throws IndexClientException {
22
		try {
23
			final String query = "";
24
		
25
			final String name = lookupLocator.getService().getResourceProfileByQuery(query);
26
		
27
			return getClientByName(name);
28
		} catch (ISLookUpDocumentNotFoundException e) {
29
			throw new IndexClientException("No index client found for: " + format + ", " + layout + ", " + interpretation, e);
30
		} catch (ISLookUpException e) {
31
			throw new IndexClientException("No index client found for: " + format + ", " + layout + ", " + interpretation, e);
32
		}
33
	}
34

  
35
	public IndexClient getClientByProfileId(final String idxId) throws IndexClientException {
36
		try {
37
			final String query = "";
38
		
39
			final String name = lookupLocator.getService().getResourceProfileByQuery(query);
40
		
41
			return getClientByName(name);
42
		} catch (ISLookUpDocumentNotFoundException e) {
43
			throw new IndexClientException("No index client found for profId: " + idxId, e);
44
		} catch (ISLookUpException e) {
45
			throw new IndexClientException("No index client found for profId: " + idxId, e);
46
		}
47
	}
48

  
49
	public IndexClient getClientByName(final String name) throws IndexClientException {
50
		for (IndexClient cl : indexClients) {
51
			if (cl.getName().equalsIgnoreCase(name)) {
52
				return cl;
53
			}
54
		}
55
		throw new IndexClientException("No index client found with name: " + name);
56
	}
57

  
58 9
}

Also available in: Unified diff