Project

General

Profile

« Previous | Next » 

Revision 28298

document viewer

View differences:

IndexClient.java
3 3
import java.io.StringReader;
4 4
import java.io.StringWriter;
5 5
import java.util.ArrayList;
6
import java.util.Collections;
6 7
import java.util.List;
7 8

  
8 9
import javax.annotation.Resource;
......
16 17
import org.dom4j.io.SAXReader;
17 18
import org.springframework.beans.factory.annotation.Required;
18 19

  
20
import com.google.common.collect.Iterables;
19 21
import com.google.common.collect.Lists;
20 22

  
21 23
import eu.dnetlib.data.provision.index.rmi.IndexService;
......
99 101
		}
100 102

  
101 103
		return list;
102
	}
104
	}	
103 105

  
104 106
	public SearchResult search(final String query, final int page) throws IndexServiceException, DocumentException, ResultSetException {
105 107

  
......
130 132
	}
131 133
	
132 134
	
135
	public String getDocument(final String id) throws IndexServiceException, ResultSetException {
136
		
137
		final String query = "objidentifier exact \"" + id.trim() + "\"";
138
		
139
		final W3CEndpointReference epr = indexLocator.getService().lookup(query, mdFormat, layout, interpretation);
140
		
141
		final ResultSetService rs = serviceResolver.getService(ResultSetService.class, epr);
142
		final String rsId = serviceResolver.getResourceIdentifier(epr);
143
		final int total = rs.getNumberOfElements(rsId);
144
		if (total != 1) {
145
			log.error("Invalid number of results (" + total + ") for query: " + query);
146
			throw new IllegalArgumentException("Invalid number of results (" + total + ") for query: " + query);
147
		}
148
		
149
		final String record = Iterables.getOnlyElement(rs.getResult(rsId, 1, 1, "WAITING"));
150
		
151
		return toDocument.evaluate(record);
152
	}
153
	
154
	
133 155
	public ServiceLocator<IndexService> getIndexLocator() {
134 156
		return indexLocator;
135 157
	}
......
201 223
	public void setToDocument(UnaryFunction<String, String> toDocument) {
202 224
		this.toDocument = toDocument;
203 225
	}
226

  
227

  
204 228
}

Also available in: Unified diff