Project

General

Profile

« Previous | Next » 

Revision 63162

[maven-release-plugin] copy for tag uoa-search-3.13.4

View differences:

modules/uoa-search/tags/uoa-search-3.13.4/pom.xml
1
<?xml version="1.0"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet45-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>uoa-search</artifactId>
11
	<packaging>jar</packaging>
12
	<version>3.13.4</version>
13
	<scm>
14
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/uoa-search/tags/uoa-search-3.13.4</developerConnection> 
15
        </scm>
16

  
17
    <repositories>
18
        <!-- Cloudera Repositories -->
19
        <repository>
20
            <snapshots>
21
                <enabled>false</enabled>
22
            </snapshots>
23
            <id>cloudera-central</id>
24
            <name>cloundera-libs-release</name>
25
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/cloudera-central</url>
26
        </repository>
27
        <repository>
28
            <id>cloudera-snapshots</id>
29
            <name>cloudera-libs-snapshot</name>
30
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/cloudera-snapshots</url>
31
        </repository>
32
        <repository>
33
            <id>typesafe</id>
34
            <name>typesafe-releases</name>
35
            <url>http://maven.research-infrastructures.eu/nexus/content/repositories/typesafe</url>
36
        </repository>
37
    </repositories>
38

  
39
	<dependencies>
40
		<dependency>
41
			<groupId>junit</groupId>
42
			<artifactId>junit</artifactId>
43
			<version>${junit.version}</version>
44
			<scope>test</scope>
45
		</dependency>
46
		<dependency>
47
			<groupId>eu.dnetlib</groupId>
48
			<artifactId>uoa-commons</artifactId>
49
			<version>[2.0.0, 3.0.0)</version>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.mockito</groupId>
53
			<artifactId>mockito-all</artifactId>
54
			<version>1.6</version>
55
		</dependency>
56
		<dependency>
57
			<groupId>org.apache.solr</groupId>
58
			<artifactId>solr-solrj</artifactId>
59
			<version>7.2.1</version>
60
            <exclusions>
61
                <exclusion>
62
                    <groupId>org.apache.zookeeper</groupId>
63
                    <artifactId>zookeeper</artifactId>
64
                </exclusion>
65
            </exclusions>
66
		</dependency>
67
        <dependency>
68
            <groupId>org.apache.zookeeper</groupId>
69
            <artifactId>zookeeper</artifactId>
70
            <version>3.4.5-cdh4.3.0</version>
71
        </dependency>
72
		<dependency>
73
			<groupId>eu.dnetlib</groupId>
74
			<artifactId>cnr-cql-utils</artifactId>
75
			<version>[2.0.0, 3.0.0)</version>
76
			<scope>compile</scope>
77
		</dependency>
78
		<dependency>
79
			<groupId>eu.dnetlib</groupId>
80
			<artifactId>cnr-blackboard-common</artifactId>
81
			<version>[2.2.1, 3.0.0)</version>
82
		</dependency>
83

  
84
		<!-- Spring MVC framework -->
85
		<dependency>
86
			<groupId>org.springframework</groupId>
87
			<artifactId>spring-webmvc</artifactId>
88
			<version>${spring.version}</version>
89
		</dependency>
90

  
91
		<dependency>
92
			<groupId>org.apache.velocity</groupId>
93
			<artifactId>velocity</artifactId>
94
			<version>1.7</version>
95
		</dependency>
96

  
97
		<dependency>
98
			<groupId>asm</groupId>
99
			<artifactId>asm</artifactId>
100
			<version>3.3.1</version>
101
		</dependency>
102
		<dependency>
103
			<groupId>com.sun.jersey</groupId>
104
			<artifactId>jersey-bundle</artifactId>
105
			<version>1.19</version>
106
		</dependency>
107
		<dependency>
108
			<groupId>org.json</groupId>
109
			<artifactId>json</artifactId>
110
			<version>20140107</version>
111
		</dependency>
112
		<dependency>
113
			<groupId>com.sun.jersey</groupId>
114
			<artifactId>jersey-server</artifactId>
115
			<version>1.19</version>
116
		</dependency>
117
		<dependency>
118
			<groupId>com.sun.jersey</groupId>
119
			<artifactId>jersey-core</artifactId>
120
			<version>1.19</version>
121
		</dependency>
122
		<dependency>
123
			<groupId>commons-validator</groupId>
124
			<artifactId>commons-validator</artifactId>
125
			<version>1.6</version>
126
		</dependency>
127
		<dependency>
128
			<groupId>org.eclipse.persistence</groupId>
129
			<artifactId>org.eclipse.persistence.moxy</artifactId>
130
			<version>2.5.0</version>
131
		</dependency>
132
		<dependency>
133
			<groupId>com.sun.jersey.contribs</groupId>
134
			<artifactId>jersey-spring</artifactId>
135
			<version>1.8</version>
136
			<exclusions>
137
				<exclusion>
138
					<groupId>org.springframework</groupId>
139
					<artifactId>spring</artifactId>
140
				</exclusion>
141
				<exclusion>
142
					<groupId>org.springframework</groupId>
143
					<artifactId>spring-core</artifactId>
144
				</exclusion>
145
				<exclusion>
146
					<groupId>org.springframework</groupId>
147
					<artifactId>spring-web</artifactId>
148
				</exclusion>
149
				<exclusion>
150
					<groupId>org.springframework</groupId>
151
					<artifactId>spring-beans</artifactId>
152
				</exclusion>
153
				<exclusion>
154
					<groupId>org.springframework</groupId>
155
					<artifactId>spring-context</artifactId>
156
				</exclusion>
157
				<exclusion>
158
					<groupId>org.springframework</groupId>
159
					<artifactId>spring-utils</artifactId>
160
				</exclusion>
161
				<exclusion>
162
					<groupId>org.springframework</groupId>
163
					<artifactId>spring-aop</artifactId>
164
				</exclusion>
165
			</exclusions>
166
		</dependency>
167
		<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
168
		<dependency>
169
			<groupId>com.google.code.gson</groupId>
170
			<artifactId>gson</artifactId>
171
			<version>2.3.1</version>
172
		</dependency>
173
		<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
174
		<dependency>
175
			<groupId>org.apache.commons</groupId>
176
			<artifactId>commons-lang3</artifactId>
177
			<version>3.5</version>
178
		</dependency>
179

  
180
		<dependency>
181
			<groupId>io.prometheus</groupId>
182
			<artifactId>simpleclient</artifactId>
183
			<version>0.6.0</version>
184
		</dependency>
185

  
186
		<dependency>
187
			<groupId>io.prometheus</groupId>
188
			<artifactId>simpleclient_servlet</artifactId>
189
			<version>0.6.0</version>
190
		</dependency>
191

  
192
		<dependency>
193
			<groupId>io.prometheus</groupId>
194
			<artifactId>simpleclient_hotspot</artifactId>
195
			<version>0.6.0</version>
196
		</dependency>
197

  
198
		<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
199
		<dependency>
200
			<groupId>io.micrometer</groupId>
201
			<artifactId>micrometer-registry-prometheus</artifactId>
202
			<version>1.2.0</version>
203
		</dependency>
204

  
205
		<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-spring-legacy -->
206
		<dependency>
207
			<groupId>io.micrometer</groupId>
208
			<artifactId>micrometer-spring-legacy</artifactId>
209
			<version>1.2.0</version>
210
		</dependency>
211

  
212

  
213
		<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
214
		<!-- AspectJ -->
215
		<dependency>
216
			<groupId>org.aspectj</groupId>
217
			<artifactId>aspectjrt</artifactId>
218
			<version>1.9.4</version>
219
		</dependency>
220
		<dependency>
221
			<groupId>org.aspectj</groupId>
222
			<artifactId>aspectjweaver</artifactId>
223
			<version>1.9.4</version>
224
		</dependency>
225

  
226
        <!-- https://mvnrepository.com/artifact/org.apache.maven/maven-model -->
227
        <dependency>
228
            <groupId>org.apache.maven</groupId>
229
            <artifactId>maven-model</artifactId>
230
            <version>3.3.9</version>
231
        </dependency>
232

  
233

  
234

  
235
    </dependencies>
236

  
237
	<build>
238
		<plugins>
239
			<plugin>
240
				<groupId>org.apache.maven.plugins</groupId>
241
				<artifactId>maven-compiler-plugin</artifactId>
242
				<configuration>
243
					<source>1.8</source>
244
					<target>1.8</target>
245
				</configuration>
246
			</plugin>
247
		</plugins>
248
	</build>
249
</project>
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/web/api/MicrometerPublisher.java
1
package eu.dnetlib.data.search.web.api;
2

  
3
import io.micrometer.prometheus.PrometheusMeterRegistry;
4
import org.springframework.beans.factory.annotation.Autowired;
5
import org.springframework.context.annotation.ComponentScan;
6
import org.springframework.http.MediaType;
7
import org.springframework.stereotype.Component;
8
import org.springframework.stereotype.Controller;
9
import org.springframework.web.bind.annotation.RequestMapping;
10
import org.springframework.web.bind.annotation.RequestMethod;
11
import org.springframework.web.bind.annotation.ResponseBody;
12

  
13
import javax.servlet.http.HttpServletRequest;
14
import javax.servlet.http.HttpServletResponse;
15

  
16
@Controller
17
@ComponentScan
18
@Component
19
public class MicrometerPublisher {
20

  
21
    @Autowired
22
    PrometheusMeterRegistry registry;
23

  
24
    @RequestMapping(method = RequestMethod.GET, value = "/metrics", produces = {MediaType.TEXT_PLAIN_VALUE})
25
    @ResponseBody
26
    public String getMetrics(HttpServletRequest request, HttpServletResponse response) throws Exception {
27
        return  registry.scrape();
28
    }
29
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/web/api/TSVResponseFormat.java
1
package eu.dnetlib.data.search.web.api;
2

  
3
/**
4
 * Created by kiatrop on 20/12/2016.
5
 */
6
public class TSVResponseFormat {
7
    public static final String organization = "Name\tProjects\tCountry\n";
8
    public static final String response = "%s%s";
9
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/web/api/HTMLResponseFormat.java
1
package eu.dnetlib.data.search.web.api;
2

  
3
/**
4
 * Created by kiatrop on 16/1/2017.
5
 */
6
public class HTMLResponseFormat {
7
    public static final String response = "<table>" +
8
            "<thead><tr>" +
9
            " <th>Title</th>" +
10
            "<th>Authors</th>" +
11
            "<th>Publication Year</th>" +
12
            "<th>DOI</th>\n" +
13
            "<th>Permanent Identifier</th>" +
14
            "<th>Publication type</th>" +
15
            "<th>Journal</th>" +
16
            "<th>Project Name (GA Number)</th>" +
17
            "<th>Access Mode</th>" +
18
            "</tr>" +
19
            "</thead>" +
20
            "<tbody>%s</tbody></table>";
21
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/micrometer/Metrics.java
1
package eu.dnetlib.data.search.micrometer;
2

  
3
import io.micrometer.core.instrument.Tags;
4
import io.micrometer.core.instrument.Timer;
5
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
6
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
7
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
8
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
9
import io.micrometer.prometheus.PrometheusMeterRegistry;
10
import org.apache.log4j.Logger;
11
import org.apache.maven.model.Dependency;
12
import org.apache.maven.model.Model;
13
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
14
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.context.annotation.Configuration;
17
import org.springframework.stereotype.Component;
18

  
19
import javax.annotation.PostConstruct;
20
import javax.ws.rs.core.Application;
21
import java.io.IOException;
22
import java.io.InputStreamReader;
23
import java.time.Duration;
24
import java.util.List;
25
import java.util.concurrent.atomic.AtomicInteger;
26

  
27

  
28
@Configuration
29
@Component
30
public class Metrics {
31

  
32
    private static final Logger logger = Logger.getLogger(Metrics.class);
33

  
34
    private static final AtomicInteger n = new AtomicInteger(1);
35

  
36
    @Autowired
37
    private PrometheusMeterRegistry registry;
38

  
39
    @PostConstruct
40
    public void init() {
41

  
42
        new JvmMemoryMetrics().bindTo(registry);
43
        new JvmGcMetrics().bindTo(registry);
44
        new JvmThreadMetrics().bindTo(registry);
45
        new UptimeMetrics().bindTo(registry);
46

  
47
        Timer.builder("search.server.response.duration").description("search response time with solr request and transformation included")
48
                .sla(Duration.ofMillis(100), Duration.ofMillis(500), Duration.ofMillis(1000), Duration.ofMillis(2000), Duration.ofMillis(2500),
49
                        Duration.ofMillis(3000),Duration.ofMillis(4000), Duration.ofMillis(5000)).register(registry);
50

  
51
        Timer.builder("solr.server.response.duration").description("solr response time")
52
                .sla(Duration.ofMillis(100), Duration.ofMillis(500), Duration.ofMillis(1000), Duration.ofMillis(2000), Duration.ofMillis(2500),
53
                        Duration.ofMillis(3000),Duration.ofMillis(4000), Duration.ofMillis(5000)).register(registry);
54

  
55
        MavenXpp3Reader reader = new MavenXpp3Reader();
56
        Model model = null;
57

  
58
        try {
59
                model = reader.read(
60
                        new InputStreamReader(
61
                                Application.class.getResourceAsStream(
62
                                        "/META-INF/maven/eu.dnetlib/uoa-search/pom.xml"
63
                                )
64
                        )
65
                );
66

  
67
        } catch (XmlPullParserException e) {
68
           logger.error("Error reading pom. ", e);
69

  
70
        } catch (IOException e) {
71
            logger.error("Error reading pom. ", e);
72
        } {
73

  
74
        }
75

  
76
        List<Dependency> list = model.getDependencies();
77
        Dependency micrometer = list.stream()
78
                .filter(dependency -> dependency.getArtifactId().equals("micrometer-registry-prometheus"))
79
                .findFirst()
80
                .get();
81

  
82
        registry.gauge("micrometer_info", Tags.of("component", model.getArtifactId()).and("scmtag", "HEAD").and("version", model.getVersion()), n);
83
        //registry.summary("search.server.response.size");
84

  
85
    }
86
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/app/plan/QueryRewriteRule.java
1
package eu.dnetlib.data.search.app.plan;
2

  
3
/**
4
 */
5
public abstract class QueryRewriteRule {
6

  
7
	protected String name = null;
8
	
9
	public QueryRewriteRule(String name) {
10
		this.name = name;
11
	}
12
	
13
	public QueryRewriteRule() {
14
		this("");
15
	}
16
	
17
	public String getName() {
18
		return name;
19
	}
20

  
21
	public void setName(String name) {
22
		this.name = name;
23
	}
24

  
25
	public abstract String apply(String query);
26
	
27
	@Override
28
	public String toString() {
29
		return "'"+name+"'";
30
	}
31
}
0 32

  
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/app/plan/CollectionRewriteRule.java
1
package eu.dnetlib.data.search.app.plan;
2

  
3
import eu.dnetlib.domain.functionality.Collection;
4
import gr.uoa.di.driver.enabling.ISLookUp;
5
import org.apache.log4j.Logger;
6

  
7
public class CollectionRewriteRule extends FieldRewriteRule {
8

  
9
	public static Logger logger = Logger.getLogger(QueryRewriteRule.class);
10
	
11
	private ISLookUp<Collection> collectionLookUp = null;
12
	
13
	public CollectionRewriteRule() {
14
		super(null, null);
15
	}
16
	
17
	public CollectionRewriteRule(String name, String fieldName) {
18
		super(name, fieldName);
19
	}
20

  
21
	public ISLookUp<Collection> getCollectionLookUp() {
22
		return collectionLookUp;
23
	}
24

  
25
	public void setCollectionLookUp(
26
			ISLookUp<eu.dnetlib.domain.functionality.Collection> collectionLookUp) {
27
		this.collectionLookUp = collectionLookUp;
28
	}
29
	
30
/*	@Override
31
	public CqlClause apply(CqlRelation relation) throws CqlException {
32
		
33
		if (!relation.getIndex().equals(fieldName)) {
34
			throw new IllegalArgumentException("Rule " + name
35
					+ " expects field " + fieldName
36
					+ " but is applied on field " + relation.getIndex());
37
		}
38
		
39
		String id = relation.getValue().substring(1, relation.getValue().length()-1);
40
		try {
41
			Collection collection = getCollectionLookUp().getById(id);
42
			if (logger.isDebugEnabled()) {
43
				logger.debug("rewrite relation '" + relation.toCqlString()
44
						+ "' as '" + collection.getRetrievalCondition() + "'");
45
			}
46
			
47
			Query query = new Query(collection.getRetrievalCondition());
48
			return query.getCqlQuery().getRoot();
49
			
50
		} catch (ISLookUpException e) {
51
			throw new CqlException(
52
					"Collection lookup for " + id + " failed.", e);
53
		}
54
	} */
55
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/solr/SolrResultSetFactory.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import eu.dnetlib.api.data.SearchServiceException;
4
import eu.dnetlib.domain.EPR;
5
import eu.dnetlib.domain.SecureDriverResource;
6
import gr.uoa.di.driver.enabling.resultset.ResultSet;
7
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory;
8
import io.micrometer.prometheus.PrometheusMeterRegistry;
9
import org.apache.log4j.Logger;
10
import org.apache.solr.client.solrj.impl.CloudSolrClient;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.z3950.zing.cql.CQLParseException;
13

  
14
import java.io.IOException;
15
import java.util.Arrays;
16
import java.util.HashMap;
17
import java.util.Map;
18

  
19
/**
20
 * Created by antleb on 2/4/14.
21
 */
22
public class SolrResultSetFactory implements ResultSetFactory {
23

  
24
    private Logger logger = Logger.getLogger(getClass());
25
    //private Map<String, CloudSolrClient> clients = new HashMap<String, CloudSolrClient>();
26

  
27
    @Autowired
28
    private PrometheusMeterRegistry prometheusMeterRegistry;
29

  
30
    private CloudSolrClient solrClient;
31
    private CloudSolrClient solrClientWithSocketTimeout;
32

  
33
    public void init(String[] zkservers, int socketTimeout) {
34
        logger.info("Initialization of clients.");
35

  
36
        logger.info("solrClient is set without socket timeout.");
37
        solrClient = new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkservers)).build();
38
        if (socketTimeout!=-1) {
39
            logger.info("solrClientWithSocketTimeout is set with socket timeout " + socketTimeout );
40
            solrClientWithSocketTimeout = new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkservers))
41
                    .withSocketTimeout(socketTimeout).build();
42
        } else {  //sudo solrClientWithSocketTimeout
43
            logger.info("solrClientWithSocketTimeout has ΝΟ actual timeout as the socketTimeout property is set to -1.");
44
            solrClientWithSocketTimeout = new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkservers)).build();
45
        }
46

  
47
    }
48

  
49
    public ResultSet<String> createResultSetWithSocketTimeout(EPR epr) throws IOException, CQLParseException, SearchServiceException {
50
        logger.info("Get RS with solrClient With SocketTimeout for EPR: " + epr);
51
        return new SolrResultSet(epr, solrClientWithSocketTimeout, prometheusMeterRegistry);
52
    }
53

  
54

  
55
    public ResultSet<String> createResultSetWithoutSocketTimeout(EPR epr) throws IOException, CQLParseException, SearchServiceException {
56
        logger.info("Get RS with solrClient Without SocketTimeout for EPR: " + epr);
57
        return new SolrResultSet(epr, solrClient, prometheusMeterRegistry);
58

  
59
    }
60

  
61
    @Override
62
    public ResultSet<String> createResultSet(EPR epr) {
63
        logger.info("Get RS with solrClient Without SocketTimeout for EPR: " + epr);
64
        try {
65
            return new SolrResultSet(epr, solrClient, prometheusMeterRegistry);
66

  
67
        } catch (IOException ioe) {
68
            logger.error("Error in search. I will return null resultSet.", ioe);
69

  
70
        } catch (CQLParseException cqlpe) {
71
            logger.error("Error in cql parse. I will return null resultSet.", cqlpe);
72

  
73
        } catch (SearchServiceException sse) {
74
            logger.error("Error in search.", sse);
75
        }
76

  
77
        return null;
78

  
79
    }
80

  
81
    @Override
82
    public <D> ResultSet<D> createResultSet(EPR epr, Class<D> resourceClass) {
83
        return (ResultSet<D>) createResultSet(epr);
84
    }
85

  
86
    @Override
87
    public <D> ResultSet<D> createResultSet(ResultSet<?> rs, Class<D> resourceClass) {
88
        throw new UnsupportedOperationException();
89
    }
90

  
91
    @Override
92
    public <D extends SecureDriverResource> ResultSet<D> createSecurityAwareRS(EPR epr, Class<D> resourceClass) {
93
        throw new UnsupportedOperationException();
94
    }
95
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/solr/SolrResultSet.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import com.google.gson.Gson;
4
import eu.dnetlib.api.data.SearchServiceException;
5
import eu.dnetlib.data.search.transform.Transformer;
6
import eu.dnetlib.data.search.transform.TransformerException;
7
import eu.dnetlib.data.search.utils.solr.SolrResultSetOptionsUtil;
8
import eu.dnetlib.data.search.utils.solr.SolrResultsFormatter;
9
import eu.dnetlib.domain.EPR;
10
import gr.uoa.di.driver.enabling.resultset.ResultSet;
11
import io.micrometer.core.instrument.Timer;
12
import io.micrometer.prometheus.PrometheusMeterRegistry;
13
import org.apache.commons.lang.StringEscapeUtils;
14
import org.apache.log4j.Logger;
15
import org.apache.solr.client.solrj.SolrClient;
16
import org.apache.solr.client.solrj.SolrServerException;
17
import org.apache.solr.client.solrj.impl.CloudSolrClient;
18
import org.apache.solr.client.solrj.response.FacetField;
19
import org.apache.solr.client.solrj.response.QueryResponse;
20
import org.apache.solr.common.SolrDocumentList;
21
import org.apache.solr.common.params.SolrParams;
22
import org.apache.solr.common.util.NamedList;
23
import org.z3950.zing.cql.CQLParseException;
24

  
25
import javax.ws.rs.core.MediaType;
26
import java.io.IOException;
27
import java.io.OutputStream;
28
import java.util.*;
29

  
30
/**
31
 * Created by antleb on 2/4/14.
32
 */
33

  
34
public class SolrResultSet implements ResultSet<String> {
35

  
36
    private Logger logger = Logger.getLogger(getClass());
37

  
38
    private EPR epr = null;
39
    public SolrClient solrClient = null;
40

  
41
    private NamedList<String> queryOpts = new NamedList<String>();
42
    long size = -1;
43

  
44
    private PrometheusMeterRegistry registry;
45

  
46
    public SolrResultSet(EPR epr, CloudSolrClient cloudSolrClient, PrometheusMeterRegistry registry)
47
            throws IOException, CQLParseException, SearchServiceException {
48
        this.epr = epr;
49
        this.solrClient = cloudSolrClient;
50

  
51
        this.queryOpts = SolrResultSetOptionsUtil.extractQueryOptions(epr.getParameter("query"));
52

  
53
        String layout = epr.getParameter("layout");
54
        String mdformat = epr.getParameter("mdformat");
55
        String interpretation = epr.getParameter("interpretation");
56

  
57
        ((CloudSolrClient)solrClient).setDefaultCollection(mdformat + "-" + layout + "-" + interpretation);
58

  
59
        this.registry = registry;
60
    }
61

  
62
    @Override
63
    public boolean isOpen() {
64
        return true;
65
    }
66

  
67
    @Override
68
    public boolean isAlive() {
69
        return true;
70
    }
71

  
72
    @Override
73
    public void close() {
74

  
75
        /* Closes the whole pull. We do not want this.
76
        try {
77
            logger.info("!!!!!!!!! !!!!!!! CLOSING !!!!!!!!! !!!!!!!!!! ");
78
            solrClient.close();
79

  
80
        } catch (IOException e) {
81
            logger.error("Error closing result set.", e);
82
        }*/
83
    }
84

  
85
    @Override
86
    public int size() {
87
        return (int) size;
88
    }
89

  
90
    @Override
91
    @Deprecated
92
    public List<String> getElements(int from, int to) {
93
        return get(from, to);
94
    }
95

  
96
    List<FacetField> facetFields = null;
97

  
98
    @Override
99
    @Deprecated
100
    public List<String> get(int from, int to) {
101
        List<String> res = new ArrayList<String>();
102

  
103
        QueryResponse rsp = null;
104

  
105
        HashMap<String, List<String>> map = new HashMap<String, List<String>>();
106

  
107
        logger.debug("from: " + from);
108
        logger.debug("to: " + to);
109

  
110

  
111
        queryOpts.add("start", from+1 + "");
112
        queryOpts.add("rows", to + 1+"");
113

  
114
        try {
115

  
116
            rsp = solrClient.query(SolrParams.toSolrParams(queryOpts));
117

  
118
            facetFields = rsp.getFacetFields();
119
            SolrDocumentList docs = rsp.getResults();
120

  
121
            if (facetFields!=null && !facetFields.isEmpty()) {
122
                for (int i = from - 1; i < to; i++) {
123
                    for (FacetField field : facetFields) {
124
                        if (field.getValueCount() > i) {
125
                            BrowseField bf = new BrowseField();
126
                            bf.setId(field.getValues().get(i).getName());
127
                            bf.setName(field.getValues().get(i).getName());
128
                            bf.setCount(field.getValues().get(i).getCount() + "");
129
                            if (map.get(field.getName()) == null) {
130
                                map.put(field.getName(), new ArrayList<String>());
131
                            }
132

  
133
                            map.get(field.getName()).add(new Gson().toJson(bf));
134
                        }
135
                    }
136
                }
137

  
138
                for (Map.Entry<String, List<String>> facetEntry : map.entrySet()) {
139
                    StringBuilder builder = new StringBuilder();
140
                    builder.append("\"" + facetEntry.getKey() + "\"" + " : ");
141
                    builder.append(facetEntry.getValue());
142
                    res.add(builder.toString());
143
                }
144
            }
145

  
146
            logger.debug("time: " + rsp.getElapsedTime());
147
            logger.debug("found: " + docs.getNumFound());
148
            logger.debug("docs: " + docs.size());
149

  
150
            for (int i = 0; i < docs.size(); i++) {
151
                String result = (String) docs.get(i).get("__result");
152
                res.add(result);
153
            }
154

  
155
            return res;
156

  
157
        } catch (SolrServerException sse) {
158
            logger.error("Fail to get results from Solr. ", sse);
159

  
160
        } catch (IOException ioe) {
161
            logger.error("Fail to get results from Solr. ", ioe);
162
        }
163

  
164
        return null;
165
    }
166

  
167
    @Override
168
    public EPR getEpr() {
169
        return null;
170
    }
171

  
172
    public Map<String,List<String>> newGet(int from, int to, String format, Transformer transformer,
173
                                           Transformer oldRefineTransformer, boolean timeout, String timeoutValue) throws SearchServiceException {
174
        List<String> refineSolrResults = new ArrayList<String>();
175
        List<String> searchSolrResults = new ArrayList<String>();
176

  
177
        QueryResponse rsp = null;
178
        HashMap<String, List<String>> map = new HashMap<String, List<String>>();
179

  
180
        if (from < 0) from = 0;
181
        if (to < 0) to = 0;
182
        queryOpts.add("start", from*to + "");
183
        queryOpts.add("rows", to +"");
184

  
185
        try {
186
            if (timeout) {
187
                if (timeoutValue != null && Integer.valueOf(timeoutValue) == -1) {
188
                    logger.warn("Timeout value is -1. Timeout will not be set for query: " + queryOpts.get("q"));
189
                    timeout = false;
190
                } else if (Integer.valueOf(timeoutValue) < 500) {
191
                    logger.warn("Timeout is less than 500ms. We fall back to the default 1000ms for query:" + queryOpts.get("q"));
192
                    queryOpts.add("timeAllowed", "500");
193
                } else if (timeout) {
194
                    queryOpts.add("timeAllowed", timeoutValue);
195
                }
196
            }
197
        } catch (NumberFormatException nfe) {
198
            logger.warn("NumberFormatException occurred. Timeout not properly set. We fall back to the default 1000ms.");
199
            queryOpts.add("timeAllowed", "500");
200
        }
201

  
202
        logger.info("timeout: " + timeout + ", timeout value: " + queryOpts.get("timeAllowed"));
203

  
204
        //queryOpts.add("f.resulthostingdatasource.facet.limit", "2");
205

  
206
        long startTime = System.nanoTime();
207

  
208
        try {
209
            io.micrometer.core.instrument.Timer.Sample timer = Timer.start(registry);
210
            rsp = solrClient.query(SolrParams.toSolrParams(queryOpts));
211
            timer.stop(registry.timer("solr.server.response.duration"));
212

  
213
            long estimatedTime = System.nanoTime() - startTime;
214
            logger.info("Solrj time " + estimatedTime/1000000 +  " milliseconds for query:" + queryOpts.get("q") +
215
                    " and facets " + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") +
216
                    " and sorts " + queryOpts.getAll("sort") + " from: "
217
                    + from + " and size " + to + " with timeout: " + timeout);
218

  
219
            /*System.out.println("Solrj time " + estimatedTime/1000000 +  " milliseconds for query:" + queryOpts.get("q") +
220
                    " and facets " + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") +
221
                    " and sorts " + queryOpts.getAll("sort") + " from: "
222
                    + from + " and size " + to);
223
            */
224
            facetFields = rsp.getFacetFields();
225

  
226
            SolrDocumentList docs = rsp.getResults();
227

  
228
            this.size = docs.getNumFound();
229

  
230
            if (facetFields!=null && !facetFields.isEmpty()) {
231
                if (format != null && format.equals(MediaType.APPLICATION_JSON)) {
232
                    for (FacetField field : facetFields) {
233
                        map.put(field.getName(), new ArrayList<String>());
234
                        BrowseField bf = null;
235
                        for (int i = 0; i < field.getValueCount(); i++) {
236
                            bf = new BrowseField();
237
                            //bf.setId(org.apache.commons.lang3.StringEscapeUtils.escapeJson(field.getValues().get(i).getName()));
238
                            bf.setId(field.getValues().get(i).getName());
239
                            String[] facetedValues = field.getValues().get(i).getName().split("\\|\\|",2);
240

  
241

  
242
                            logger.debug("faceted values " + Arrays.toString(facetedValues));
243

  
244
                            if (facetedValues.length > 1) {
245
                                //bf.setName(org.apache.commons.lang3.StringEscapeUtils.escapeJson(facetedValues[1]));
246
                                bf.setName(facetedValues[1]);
247
                                logger.debug("faceted values [1] " + facetedValues[1]);
248

  
249
                            } else if (field.getValues().get(i).getName().split("_\\:\\:",2).length > 1) {
250
                                //bf.setName(org.apache.commons.lang3.StringEscapeUtils.escapeJson(field.getValues().get(i).getName().split("\\:\\:",2)[1]).replaceAll("\\:\\:", "\\|"));
251
                                bf.setName(field.getValues().get(i).getName().split("\\:\\:",2)[1].replaceAll("\\:\\:", "\\|"));
252

  
253
                            } else {
254
                                //bf.setName(org.apache.commons.lang3.StringEscapeUtils.escapeJson(field.getValues().get(i).getName()));
255
                                bf.setName(field.getValues().get(i).getName());
256
                            }
257

  
258
                            bf.setCount(field.getValues().get(i).getCount() + "");
259
                            map.get(field.getName()).add(new Gson().toJson(bf));
260
                        }
261

  
262
                    }
263

  
264
                    StringBuilder builder = null;
265

  
266
                    for (Map.Entry<String, List<String>> facetEntry : map.entrySet()) {
267
                        builder = new StringBuilder();
268
                        builder.append("\"" + facetEntry.getKey() + "\"" + " : ");
269
                        builder.append(facetEntry.getValue());
270
                        refineSolrResults.add(builder.toString());
271
                    }
272

  
273
                } else { //the old implementation & xml as default
274
                    logger.debug("Creating old browse results.");
275
                    createXmlRefineFields(refineSolrResults, oldRefineTransformer);
276
                }
277
            }
278

  
279
            startTime = System.nanoTime();
280

  
281
            for (int i = 0; i < docs.size(); i++) {
282
                String result = (String) docs.get(i).get("__result");
283
                //logger.debug("["+ i +"]: " + docs.get(i).get("__result"));
284

  
285
                try {
286
                    if (transformer != null) {
287
                        //logger.debug("1 >>>>>>" + result);
288
                        String xml = result.replaceAll("<em>","").replaceAll("</em>","");
289
                        result = transformer.transform(xml);
290
                        //logger.debug("2 >>>>>>" + result);
291
                    }
292

  
293
                } catch (TransformerException te) {
294
                    logger.warn("Error transforming " + result, te);
295
                    continue;
296
                }
297

  
298
                if (format != null && format.equals(MediaType.APPLICATION_JSON)) {
299
                    searchSolrResults.add(SolrResultsFormatter.xml2Json(result));
300
                } else { // default xml
301
                    searchSolrResults.add(result);
302
                }
303
            }
304

  
305
            estimatedTime = System.nanoTime() - startTime;
306
            logger.info("Internal transformation time " + estimatedTime/1000000 +  " milliseconds for query:" + queryOpts.get("q") +
307
                    " and facets " + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") + " from: "
308
                    + from + " and size " + to);
309

  
310
            Map<String,List<String>> response = new HashMap<String, List<String>>();
311

  
312
            //logger.debug("refine results " + refineSolrResults);
313
            //logger.info("search results SIZE " + searchSolrResults.size());
314
            //logger.info("search results " + searchSolrResults);
315

  
316

  
317
            response.put("refine",refineSolrResults);
318
            response.put("search", searchSolrResults);
319

  
320
            return response;
321

  
322
        } catch (SolrServerException sse) {
323
            logger.error("Error calling Solr for  query:" + queryOpts.get("q") + " and facets "
324
                    + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") + " from: " + from +
325
                    " and size " + to, sse);
326
            throw new SearchServiceException("Error contacting Solr.", sse);
327

  
328
        } catch (IOException ioe) {
329
            logger.error("Error calling Solr for  query:" + queryOpts.get("q") + " and facets "
330
                    + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") + " from: " + from +
331
                    " and size " + to, ioe);
332
            throw new SearchServiceException("Error reading results from Solr.", ioe);
333

  
334
        }
335
    }
336

  
337
    /**
338
     * limit is the maximum number of results the cursor get is allowed to fetch. If limit is set to -1 all
339
     * results are returned.
340
     */
341
    public void cursorGet(Transformer transformer, int limit, OutputStream os) throws SolrServerException, SearchServiceException {
342

  
343
        int rows = 500;
344
        int limitCounter = -1;
345

  
346
        queryOpts.add("start", "0");
347
        queryOpts.add("rows", "0");
348
        queryOpts.remove("rows");
349
        queryOpts.add("rows", rows+"");
350
        queryOpts.add("fl", "__result");
351
        queryOpts.add("shards.tolerant","true");
352
        queryOpts.add("cursorMark", "*");
353
        queryOpts.add("sort", "__indexrecordidentifier asc");
354

  
355
        String cursorMark = "*";
356
        String nextCursorMark = "";
357

  
358
        if ( limit > 0 ) {
359
            limitCounter = limit/rows;
360
            logger.info("limit counter " + limitCounter);
361
        }
362

  
363
        try {
364
            QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts));
365

  
366
            while (!cursorMark.equals(nextCursorMark) && ( limitCounter > 0 || limitCounter == -1)) {
367
                //logger.info(">> " + limitCounter);
368
                resp = solrClient.query(SolrParams.toSolrParams(queryOpts));
369
                cursorMark = nextCursorMark;
370
                nextCursorMark = resp.getNextCursorMark();
371

  
372
                for (int i = 0; i < resp.getResults().size(); i++) {
373
                    if (transformer != null) {
374
                        String result = null;
375
                        try {
376
                            logger.debug("PRE RESULT " + resp.getResults().get(i).get("__result"));
377
                            result = transformer.transform((String) resp.getResults().get(i).get("__result"));
378
                            logger.debug("RESULT " + result);
379

  
380
                        } catch (TransformerException te) {
381
                            logger.warn("Error transforming " + result, te);
382
                            continue;
383
                        }
384

  
385
                        try {
386
                            os.write(result.getBytes());
387
                            os.flush();
388
                        } catch (IOException e) {
389
                            logger.error("Cursor get... ", e);
390
                            continue;
391
                        }
392
                    }
393
                }
394

  
395
                queryOpts.remove("cursorMark");
396
                queryOpts.add("cursorMark", nextCursorMark);
397
                limitCounter--;
398
            }
399

  
400
        } catch (IOException ioe) {
401
            logger.error("Error executing solr query. ", ioe);
402
        }
403
    }
404

  
405

  
406
    //TODO get rid of this as soon as Joomla portal is out
407
    //Just copied and refactored the old one...
408
    @Deprecated
409
    private void createXmlRefineFields(List<String> res, Transformer oldRefineTransformer) {
410
        int max = -12;
411

  
412
        for (FacetField field:facetFields) {
413
            logger.debug("field " + field.getName() + " has count " + field.getValueCount());
414

  
415
            if (field.getValueCount() > max) {
416
                max = field.getValueCount();
417
            }
418
        }
419

  
420
        logger.debug("max " + max);
421

  
422
        for (int i = 0; i < max; i++) {
423
            StringBuilder sb = new StringBuilder();
424

  
425
            sb.append("<row>");
426
            for (FacetField field:facetFields) {
427
                if (field.getValueCount() > i) {
428
                    sb.append("<groupresult field=\"").append(field.getName()).append("\">");
429
                    sb.append("<count>").append(field.getValues().get(i).getCount()).append("</count>");
430
                    sb.append("<originalValue>").append(StringEscapeUtils.escapeXml(field.getValues().get(i).getName())).append("</originalValue>");
431

  
432
                    String[] facetValues = field.getValues().get(i).getName().split("\\|\\|");
433
                    if(facetValues.length > 1) {
434
                        sb.append("<value>").append(StringEscapeUtils.escapeXml(facetValues[1])).append("</value>");
435
                    } else {
436
                        sb.append("<value>").append(StringEscapeUtils.escapeXml(facetValues[0])).append("</value>");
437
                    }
438
                    sb.append("</groupresult>");
439
                }
440
            }
441
            sb.append("</row>");
442

  
443
            try {
444
                //logger.debug("row: " + sb.toString());
445
                //logger.debug("row2: " + oldRefineTransformer.transform(sb.toString()));
446

  
447
                //TODO remove
448
                res.add(oldRefineTransformer.transform(sb.toString()));
449

  
450
            } catch (TransformerException te) {
451
                logger.error("Cannot transform refine for: " + sb.toString(), te);
452
            }
453
        }
454
    }
455

  
456
 /*   public static void main(String[] args) throws IOException, CQLParseException, SolrServerException {
457
        CloudSolrServer solrClient = new CloudSolrServer("beta.solr.openaire.eu:9983");
458
        solrClient.setDefaultCollection("DMF-index-openaire");
459

  
460
        NamedList<String> queryOpts = new NamedList<String>();
461

  
462
        //q=*:*&start=0&rows=10&cursorMark=*&sort=dateofcollection asc
463
        queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("objIdentifier = acm_________::0002c24f82c295e925a2bdf7bbf49bfc").asLucene());
464
        queryOpts.add("start", "0");
465
        queryOpts.add("rows", "1");
466
        queryOpts.add("fl", "__result");
467
        queryOpts.add("shards.tolerant","true");
468
        queryOpts.add("cursorMark", "*");
469
        queryOpts.add("sort", "__indexrecordidentifier asc");
470

  
471

  
472
        //queryOpts.add("q", new CqlTranslatorImpl().getTranslatedQuery("oaftype exact project").asLucene());
473
        NamedList<String> extraOpts = new NamedList<String>();
474

  
475
        QueryResponse resp = solrClient.query(SolrParams.toSolrParams(queryOpts));
476

  
477
        System.out.println("results " + resp.getResults().size());
478

  
479
        String cursorMark = "*";
480
        String nextCursorMark = "";
481

  
482
        int curs = 0;
483
        while (!cursorMark.equals(nextCursorMark)) {
484
            System.out.println("cursor " + cursorMark);
485
            System.out.println("next cursor " + nextCursorMark);
486
            cursorMark = nextCursorMark;
487
            for (int i = 0; i < resp.getResults().size(); i++) {
488
                String result = ((ArrayList<String>) resp.getResults().get(i).get("__result")).get(0);
489
                //System.out.println(result);
490
                resp = solrClient.query(SolrParams.toSolrParams(queryOpts));
491
            }
492
            nextCursorMark = resp.getNextCursorMark();
493
            queryOpts.add("cursorMark", nextCursorMark);
494

  
495
            System.out.println("CURS " + curs);
496
            curs ++;
497

  
498
        }
499

  
500

  
501
        //System.out.println((new CqlTranslatorImpl().getTranslatedQuery("objIdentifier = acm_________::0002c24f82c295e925a2bdf7bbf49bfc").asLucene()));
502

  
503

  
504

  
505
        //extraOpts.add("start", "1");
506
       // extraOpts.add("rows", "10");
507
       // extraOpts.addAll(queryOpts);
508

  
509
        //queryOpts.add("facet", "true");
510
        //TranslatedQuery translatedQuery = new CqlTranslatorImpl().getTranslatedQuery("oaftype=result sortBy resultdateofacceptance/sort.descending");
511

  
512
     //   queryOpts.add("q", "oaftype=project");
513
        //queryOpts.add("facet", "true");
514
        //queryOpts.add("facet.mincount", "1");
515
        //queryOpts.add("fq", "popularity");
516

  
517

  
518

  
519
//        queryOpts.put("fq", new CqlTranslatorImpl().getTranslatedQuery("").asLucene());
520
       // queryOpts.add("facet.field", "contextid");
521
       //  queryOpts.add("facet.field", "contextname");
522
       //  queryOpts.add("facet.mincount", "1");
523
       //  queryOpts.add("facet.threads", "10");
524
       // System.out.println(translatedQuery.getOptions().getSort().getMode());
525
       // System.out.println(translatedQuery.getOptions().getSort().getField());
526

  
527
        //queryOpts.add("sort", translatedQuery.getOptions().getSort().getField() + " " + translatedQuery.getOptions().getSort().getMode() );
528

  
529

  
530

  
531
/*        QueryResponse resp = null;
532
        synchronized (solrClient) {
533
            resp = solrClient.query(SolrParams.toSolrParams(extraOpts));
534
        }*/
535
//        System.out.println("time: " + resp.getElapsedTime());
536
    //System.out.println("results: " + resp.getResults());
537

  
538
/*      System.out.println(resp.getFacetField("contextname").getValueCount());
539

  
540
        for (FacetField.Count count:resp.getFacetField("contextname").getValues())
541
            System.out.println(count.getName() + " : " +  count.getCount());
542

  
543

  
544
        int max = -12;
545

  
546
        for (FacetField field:resp.getFacetFields()) {
547
            if (field.getValueCount() > max)
548
                max = field.getValueCount();
549

  
550
        }
551

  
552
        System.out.println("max: " + max);
553
*/
554
 //   }
555

  
556
//    @Override
557
//    public EPR getEpr() {
558
//        return epr;
559
//   }
560
}
561

  
562
class BrowseField {
563
    String name;
564

  
565
    public String getName() {
566
        return name;
567
    }
568

  
569
    public void setName(String name) {
570
        this.name = name;
571
    }
572

  
573
    public String getId() {
574
        return id;
575
    }
576

  
577
    public void setId(String id) {
578
        this.id = id;
579
    }
580

  
581
    public String getCount() {
582
        return count;
583
    }
584

  
585
    public void setCount(String count) {
586
        this.count = count;
587
    }
588

  
589
    String id;
590
    String count;
591

  
592

  
593
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/solr/SolrClientLocator.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import eu.dnetlib.api.data.IndexService;
4
import eu.dnetlib.api.enabling.ISLookUpService;
5
import eu.dnetlib.api.enabling.ISLookUpServiceException;
6
import gr.uoa.di.driver.util.ServiceLocator;
7
import org.apache.log4j.Logger;
8

  
9
import java.util.List;
10

  
11
/**
12
 * Created by antleb on 2/4/14.
13
 */
14
public class SolrClientLocator implements ServiceLocator<IndexService> {
15
    private Logger logger = Logger.getLogger(getClass());
16

  
17
    private SolrIndexClient indexClient = null;
18
    private ServiceLocator<ISLookUpService> lookUpServiceServiceLocator = null;
19
    private String interpretation = null;
20

  
21
    private String cachedUrl = null;
22

  
23
    @Override
24
    public IndexService getService() {
25
        if (indexClient == null) {
26
            indexClient = locateIndexService();
27
        }
28

  
29
        return indexClient;
30
    }
31

  
32
    private SolrIndexClient locateIndexService() {
33
        SolrIndexClient client = new SolrIndexClient();
34

  
35
        try {
36
            List<String> urls = lookUpServiceServiceLocator.getService().quickSearchProfile("for $x in //RESOURCE_PROFILE//PROTOCOL[./@name='solr'] return data($x/@address)");
37

  
38
            if (urls.size() > 0) {
39
                logger.debug("cached url " + cachedUrl);
40
                cachedUrl = chooseIndexService(urls);
41

  
42
            } else {
43
                cachedUrl = getCachedIndexService(urls);
44
                logger.warn("Falling back to cached value for index : " + cachedUrl);
45
                throw new IllegalArgumentException("Could not locate an index service with a SOLR interface");
46
            }
47

  
48
        } catch (ISLookUpServiceException ise) {
49
            logger.warn("Error locating service", ise);
50

  
51
        } finally {
52
            logger.warn("Falling back to cached value for index : " + cachedUrl);
53
            client.setSolrServerUrl(cachedUrl);
54
            
55
            client.setInterpretation(this.interpretation);
56
        }
57

  
58
        return client;
59
    }
60

  
61
    private String getCachedIndexService(List<String> urls) {
62
        if (cachedUrl.equals("${services.index.default.url}"))
63
            return urls.get(0);
64
        return cachedUrl;
65
    }
66

  
67
    private String chooseIndexService(List<String> urls) {
68
        return urls.get(0);
69
    }
70

  
71

  
72
    public ServiceLocator<ISLookUpService> getLookUpServiceServiceLocator() {
73
        return lookUpServiceServiceLocator;
74
    }
75

  
76
    public void setLookUpServiceServiceLocator(ServiceLocator<ISLookUpService> lookUpServiceServiceLocator) {
77
        this.lookUpServiceServiceLocator = lookUpServiceServiceLocator;
78
    }
79

  
80
    public String getInterpretation() {
81
        return interpretation;
82
    }
83

  
84
    public void setInterpretation(String interpretation) {
85
        this.interpretation = interpretation;
86
    }
87

  
88
    public String getCachedUrl() {
89
        return cachedUrl;
90
    }
91

  
92
    public void setCachedUrl(String cachedUrl) {
93
        this.cachedUrl = cachedUrl;
94
    }
95
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/solr/SolrIndexClient.java
1
package eu.dnetlib.data.search.solr;
2

  
3
import eu.dnetlib.api.DriverServiceException;
4
import eu.dnetlib.api.data.IndexService;
5
import eu.dnetlib.api.data.IndexServiceException;
6
import eu.dnetlib.domain.EPR;
7
import eu.dnetlib.domain.ServiceIdentity;
8
import eu.dnetlib.domain.data.Hint;
9
import eu.dnetlib.domain.enabling.Notification;
10

  
11
import java.util.List;
12

  
13
/**
14
 * Created by antleb on 2/4/14.
15
 */
16
public class SolrIndexClient implements IndexService {
17
    private String solrServerUrl = null;
18

  
19
    private String interpretation = null;
20

  
21
    @Override
22
    public EPR indexLookup(String id, String query, String mdformat, String layout) throws IndexServiceException {
23
        EPR epr = new EPR();
24

  
25
        epr.setAddress(solrServerUrl);
26
        epr.setParameter("action", "lookup");
27
        epr.setParameter("id", id);
28
        epr.setParameter("query", query);
29
        epr.setParameter("mdformat", mdformat);
30
        epr.setParameter("layout", layout);
31
        epr.setParameter("interpretation", this.interpretation);
32

  
33
        return epr;
34
    }
35

  
36
    @Override
37
    public EPR getBrowsingStatistics(String query, String index, String mdFormatId, String layoutId) throws IndexServiceException {
38
        EPR epr = new EPR();
39

  
40
        epr.setAddress(solrServerUrl);
41
        epr.setParameter("action", "browse");
42
        epr.setParameter("id", index);
43
        epr.setParameter("query", query);
44
        epr.setParameter("mdformat", mdFormatId);
45
        epr.setParameter("layout", layoutId);
46
        epr.setParameter("interpretation", this.interpretation);
47

  
48
        return epr;
49
    }
50

  
51
    public void newMethod(){}
52

  
53
    public EPR getBrowsingStatistics2(String query, String index, String mdFormatId, String layoutId) throws IndexServiceException {
54
        EPR epr = new EPR();
55

  
56
        epr.setAddress(solrServerUrl);
57
        epr.setParameter("action", "browse");
58
        epr.setParameter("id", index);
59
        epr.setParameter("query", query);
60
        epr.setParameter("mdformat", mdFormatId);
61
        epr.setParameter("layout", layoutId);
62
        epr.setParameter("interpretation", this.interpretation);
63

  
64
        return epr;
65
    }
66

  
67
    @Override
68
    public Hint suggestiveSearch(String s, String s2, String s3, String s4, String s5) throws IndexServiceException {
69
        throw new UnsupportedOperationException();
70
    }
71

  
72
    @Override
73
    public List<String> getListOfIndices() throws IndexServiceException {
74
        throw new UnsupportedOperationException();
75
    }
76

  
77
    @Override
78
    public String getIndexStatistics(String s) throws IndexServiceException {
79
        throw new UnsupportedOperationException();
80
    }
81

  
82
    @Override
83
    public String getListOfIndicesCSV() throws IndexServiceException {
84
        throw new UnsupportedOperationException();
85
    }
86

  
87
    @Override
88
    public ServiceIdentity identify() {
89
        throw new UnsupportedOperationException();
90
    }
91

  
92
    @Override
93
    public void notify(Notification notification) throws DriverServiceException {
94
        throw new UnsupportedOperationException();
95
    }
96

  
97
    public String getSolrServerUrl() {
98
        return solrServerUrl;
99
    }
100

  
101
    public void setSolrServerUrl(String solrServerUrl) {
102
        this.solrServerUrl = solrServerUrl;
103
    }
104

  
105
    public String getInterpretation() {
106
        return interpretation;
107
    }
108

  
109
    public void setInterpretation(String interpretation) {
110
        this.interpretation = interpretation;
111
    }
112
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/app/plan/FieldRewriteRule.java
1
package eu.dnetlib.data.search.app.plan;
2

  
3
/**
4
 */
5
public abstract class FieldRewriteRule {
6

  
7
	protected String name = null;
8
	protected String fieldName = null;
9
	
10
	public FieldRewriteRule(String name, String fieldName) {
11
		this.name = name;
12
		this.fieldName = fieldName;
13
	}
14
	
15
	public String getFieldName() {
16
		return fieldName;
17
	}
18
	
19
	public void setFieldName(String fieldName) {
20
		this.fieldName = fieldName;
21
	}
22
	
23
	public String getName() {
24
		return name;
25
	}
26
	
27
	public void setName(String name) {
28
		this.name = name;
29
	}
30

  
31
	//public abstract CqlClause apply(CqlRelation relation) throws CqlException;
32
	
33
	@Override
34
	public String toString() {
35
		return name;
36
	}
37
}
modules/uoa-search/tags/uoa-search-3.13.4/src/main/java/eu/dnetlib/data/search/web/SearchServiceContextUtils.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.search.web;
5

  
6
import eu.dnetlib.api.data.SearchService;
7
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory;
8
import org.springframework.context.ApplicationContext;
9
import org.springframework.web.context.support.WebApplicationContextUtils;
10
import org.w3c.dom.Document;
11
import org.w3c.dom.Element;
12
import org.xml.sax.InputSource;
13
import org.xml.sax.SAXException;
14

  
15
import javax.servlet.ServletContext;
16
import javax.servlet.http.HttpServletRequest;
17
import javax.xml.parsers.DocumentBuilder;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff