Added the social data search client library

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-data-search-client@122876 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-05 16:38:07 +00:00
parent df0ffc8dde
commit 22266ce2ed
22 changed files with 856 additions and 0 deletions

26
.classpath Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>social-data-search-client</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

2
distro/INSTALL Normal file
View File

@ -0,0 +1,2 @@

7
distro/LICENSE Normal file
View File

@ -0,0 +1,7 @@
gCube System - License
------------------------------------------------------------
The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl).
The software and documentation is provided by its authors/distributors "as is" and no expressed or
implied warranty is given for its use, quality or fitness for a particular case.

6
distro/MAINTAINERS Normal file
View File

@ -0,0 +1,6 @@
Mantainers
-------
* Costantino Perciante (costantino.perciante@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo".

35
distro/README Normal file
View File

@ -0,0 +1,35 @@
The gCube System - Social Library
------------------------------------------------------------
This work is partially funded by the European Commission in the
context of the iMarine project (www.i-marine.eu), under the 1st call of FP7 IST priority.
Authors
-------
Costantino Perciante
*
Version and Release Date
------------------------
Feb 2016
Description
-----------
Social Data Search Client
Download information
--------------------
Source code is available from SVN:
https://svn.d4science.research-infrastructures.eu/gcube/trunk/socialnetworking/social-data-search-client
Binaries can be downloaded from:
http://software.d4science.research-infrastructures.eu/
Documentation
-------------
Documentation is available on-line from the Projects Documentation Wiki:
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

6
distro/changelog.xml Normal file
View File

@ -0,0 +1,6 @@
<ReleaseNotes>
<Changeset component="org.gcube.socialnetworking.social-data-search-client.1-0-0"
date="2016-02-29">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

48
distro/descriptor.xml Normal file
View File

@ -0,0 +1,48 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
<fileSet>
<directory>target/apidocs</directory>
<outputDirectory>/${artifactId}/doc/api</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<fileMode>755</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>./</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

25
distro/profile.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>gCube Social Networking Library</Description>
<Class>Portal</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

1
distro/svnpath.txt Normal file
View File

@ -0,0 +1 @@
${scm.url}

233
pom.xml Normal file
View File

@ -0,0 +1,233 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-search-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Social Data Search Client</name>
<description>
This library extends the functionalities of the elastic-search client in order to perform full-text search
on a previously created elasticsearch index that contains posts/comments present in the Social gcube Cassandra cluster.
</description>
<scm>
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/${serviceClass}/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/${serviceClass}/${project.artifactId}</developerConnection>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/${serviceClass}/${project.artifactId}</url>
</scm>
<properties>
<elasticSearchVersion>2.2.0</elasticSearchVersion>
<guavaVersion>18.0</guavaVersion>
<serviceClass>social-networking</serviceClass>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticSearchVersion}</version>
</dependency>
<dependency>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>notifications-common-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guavaVersion}</version>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>compress-lzf</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<!-- <descriptorRefs> -->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef> -->
<!-- </descriptorRefs> -->
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,146 @@
package org.gcube.socialnetworking.social_data_search_client;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The elasticsearch client for gcube portlets.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ElasticSearchClientImpl implements ElasticSearchClientInterface{
//logger
public static final Logger _log = LoggerFactory.getLogger(ElasticSearchClientImpl.class);
// the elasticsearch client
private TransportClient client;
// the cluster name: it must be the same among all cluster's nodes
private String clusterName;
// list of hosts to contact
private List<String> hostsToContact;
// private port number
private List<Integer> portNumbers;
/**
* Build an elasticsearch client to be queried.
* @param scope the scope in the infrastructure
* @throws Exception
*/
public ElasticSearchClientImpl(String scope) throws Exception {
// retrieve ElasticSearch Endpoint and set hosts/port number
ElasticSearchRunningCluster elasticCluster = new ElasticSearchRunningCluster(scope);
// save info
clusterName = elasticCluster.getClusterName();
hostsToContact = elasticCluster.getHosts();
portNumbers = elasticCluster.getPorts();
_log.debug("Creating elasticsearch client for hosts = " + hostsToContact + ", port = " + portNumbers + " and "
+ " cluster's name = " + clusterName);
// set cluster's name to check and the sniff property to true.
// Cluster's name: each node must have this name.
// Sniff property: allows the client to recover cluster's structure.
// Look at https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
Settings settings = Settings.settingsBuilder()
.put("cluster.name", this.clusterName)
.put("client.transport.sniff", true)
.build();
// build the client
client = TransportClient.builder().settings(settings).build();
// add the nodes to contact
for (int i = 0; i < hostsToContact.size(); i++){
try {
client.addTransportAddress(
new InetSocketTransportAddress(
InetAddress.getByName(hostsToContact.get(i)), portNumbers.get(i))
);
} catch (UnknownHostException e) {
_log.debug("Error while adding " + hostsToContact.get(i) + ":" + portNumbers.get(i) + " as host to be contacted.");
}
}
_log.debug("Connection to ElasticSearch cluster done.");
}
@Override
public List<EnhancedFeed> searchInEnhancedFeeds(String query, String vreID, int hits, boolean isPhraseSearch){
List<EnhancedFeed> toReturn = new ArrayList<>();
MultiMatchQueryBuilder mq = QueryBuilders.multiMatchQuery(
query,
IndexFields.EF_FEED_TEXT + "^2", // weight of 2 for feed's description
IndexFields.EF_ATTACHMENT_NAME,
IndexFields.EF_PREVIEW_DESCRIPTION,
IndexFields.EF_COMMENT_TEXT).
type(Type.MOST_FIELDS);
SearchResponse response = client.prepareSearch(IndexFields.INDEX_NAME)
.setTypes(vreID == null ? IndexFields.EF_FEEDS_TABLE : IndexFields.EF_FEEDS_TABLE + vreID)
.setQuery(mq)
.setFrom(0).setSize(hits).setExplain(true)
.addHighlightedField(IndexFields.EF_FEED_TEXT)
.addHighlightedField(IndexFields.EF_ATTACHMENT_NAME)
.addHighlightedField(IndexFields.EF_PREVIEW_DESCRIPTION)
.addHighlightedField(IndexFields.EF_COMMENT_TEXT)
.setHighlighterPreTags("<em>")
.setHighlighterPostTags("</em>")
.execute()
.actionGet();
_log.debug("The search took " + response.getTookInMillis() + " ms");
SearchHit[] results = response.getHits().getHits();
_log.debug("Number of hits is " + results.length);
ObjectMapper mapper = new ObjectMapper();
for (SearchHit hit : results) {
//JSON from String to Object
EnhancedFeed enhFeed;
try {
_log.debug(hit.getSourceAsString());
enhFeed = mapper.readValue(hit.getSourceAsString(), EnhancedFeed.class);
// add to the return set
toReturn.add(enhFeed);
} catch (IOException e) {
_log.error(e.toString());
}
}
return toReturn;
}
}

View File

@ -0,0 +1,19 @@
package org.gcube.socialnetworking.social_data_search_client;
import java.util.List;
import org.gcube.portal.databook.shared.EnhancedFeed;
public interface ElasticSearchClientInterface {
/**
* Given a query, the method find matching enhanced feeds into the elasticsearch index.
* @param query the query to match
* @param vreID specify if you want to lookup enhanced feeds only in a certain vre
* @param hits the maximum number of hits to return
* @param isPhraseSearch if you want to exactly match a phrase
* @return A list if matching enhanced feeds or nothing
*/
public List<EnhancedFeed> searchInEnhancedFeeds(String query, String vreID, int hits, boolean isPhraseSearch);
}

View File

@ -0,0 +1,133 @@
package org.gcube.socialnetworking.social_data_search_client;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.socialnetworking.social_data_search_client.ex.NoElasticSearchRuntimeResourceException;
import org.gcube.socialnetworking.social_data_search_client.ex.ServiceEndPointException;
import org.gcube.socialnetworking.social_data_search_client.ex.TooManyRunningClustersException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Retrieve elasticsearch's running instance information in the infrastructure.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ElasticSearchRunningCluster {
//logger
private static final Logger _log = LoggerFactory.getLogger(ElasticSearchRunningCluster.class);
//properties
private final static String RUNTIME_RESOURCE_NAME = "SocialPortalDataIndex";
private final static String PLATFORM_NAME = "ElasticSearch";
// retrieved data
private List<String> hosts = new ArrayList<String>();
private List<Integer> ports = new ArrayList<Integer>();
private String clusterName;
public ElasticSearchRunningCluster(String infrastructure) throws Exception{
try {
List<ServiceEndpoint> resources = getConfigurationFromIS(infrastructure);
if (resources.size() > 1) {
_log.error("Too many Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" in this scope");
throw new TooManyRunningClustersException("There exist more than 1 Runtime Resource in this scope having name "
+ RUNTIME_RESOURCE_NAME + " and Platform " + PLATFORM_NAME + ". Only one allowed per infrasrtucture.");
}
else if (resources.size() == 0){
_log.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Platform " + PLATFORM_NAME + " in this scope.");
throw new NoElasticSearchRuntimeResourceException();
}
else {
try{
_log.debug(resources.toString());
for (ServiceEndpoint res : resources) {
Iterator<AccessPoint> accessPointIterator = res.profile().accessPoints().iterator();
while (accessPointIterator.hasNext()) {
ServiceEndpoint.AccessPoint accessPoint = (ServiceEndpoint.AccessPoint) accessPointIterator
.next();
// add this host
hosts.add(accessPoint.address().split(":")[0]);
// save the port
int port = Integer.parseInt(accessPoint.address().split(":")[1]);
ports.add(port);
// save the name of the cluster (this should be unique)
clusterName = accessPoint.name();
}
}
}catch(Exception e ){
_log.error(e.toString());
throw new ServiceEndPointException();
}
}
} catch (Exception e) {
_log.error(e.toString());
throw e;
}
}
/**
* Retrieve endpoints information from IS
* @return list of endpoints for elasticsearch
* @throws Exception
*/
private List<ServiceEndpoint> getConfigurationFromIS(String infrastructure) throws Exception{
PortalContext context = PortalContext.getConfiguration();
String scope = "/";
if(infrastructure != null && !infrastructure.isEmpty())
scope += infrastructure;
else
scope += context.getInfrastructureName();
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
query.addCondition("$resource/Profile/Platform/Name/text() eq '"+ PLATFORM_NAME +"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query);
ScopeProvider.instance.set(currScope);
return toReturn;
}
public List<String> getHosts() {
return hosts;
}
public List<Integer> getPorts() {
return ports;
}
public String getClusterName() {
return clusterName;
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.socialnetworking.social_data_search_client;
/**
* The fields used to build up the index.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class IndexFields {
// name of the index
public static final String INDEX_NAME = "social";
// table for comments
public static final String COMMENT_TABLE = "comments";
// table for feeds
public static final String FEED_TABLE = "feeds";
// table for enhanced feeds
public static final String EF_FEEDS_TABLE = "enhanced_feeds";
// comment table's fields
public static final String COMMENT_TEXT = "description";
public static final String COMMENT_PARENT_ID = "parent_id";
// feed table's fields
public static final String FEED_TEXT = "description";
public static final String FEED_TYPE = "type";
public static final String FEED_VRE_ID = "vre_id";
// enhanced feeds' fields
public static final String EF_ATTACHMENT_NAME = "attachments.name";
public static final String EF_FEED_TEXT = "feed.description";
public static final String EF_COMMENT_TEXT = "comments.text";
public static final String EF_PREVIEW_DESCRIPTION = "feed.linkTitle";
}

View File

@ -0,0 +1,24 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* No elasticsearch cluster in the infrastructure found exception.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class NoElasticSearchRuntimeResourceException extends Exception {
private static final long serialVersionUID = -40748130477807648L;
private static final String DEFAULT_MESSAGE = "No ElasticSearch cluster instance for this scope!";
public NoElasticSearchRuntimeResourceException(){
super(DEFAULT_MESSAGE);
}
public NoElasticSearchRuntimeResourceException(String message) {
super(message);
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* Exception thrown when it is not possible retrieve information from the ServiceEndpoint
* related to ElasticSearch
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ServiceEndPointException extends Exception {
private static final long serialVersionUID = 5378333924429281681L;
private static final String DEFAULT_MESSAGE = "Unable to retrieve information from ElasticSearch endpoint!";
public ServiceEndPointException(){
super(DEFAULT_MESSAGE);
}
public ServiceEndPointException(String string) {
super(string);
}
}

View File

@ -0,0 +1,23 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* Too many clusters in this scope exception.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class TooManyRunningClustersException extends Exception {
private static final long serialVersionUID = -4112724774153676227L;
private static final String DEFAULT_MESSAGE = "Too many ElasticSearch cluster instances for this scope!";
public TooManyRunningClustersException(){
super(DEFAULT_MESSAGE);
}
public TooManyRunningClustersException(String message) {
super(message);
}
}

View File

@ -0,0 +1,27 @@
package org.gcube.socialnetworking.social_data_search_client;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class Tests
{
@Test
public void query() throws Exception{
List<String> hosts = new ArrayList<String>();
hosts.add("localhost");
ElasticSearchClientImpl el = new ElasticSearchClientImpl("gcube");
// try to query
List<EnhancedFeed> enFeeds = el.searchInEnhancedFeeds("argentina slow Screen Shot 2016-01-26 at 12.39.30.png", "/gcube/devsec/devVRE", 10, false);
for (EnhancedFeed enFeed : enFeeds) {
System.err.println("Result is " + enFeed.toString());
}
}
}