37 lines
1.0 KiB
Java
37 lines
1.0 KiB
Java
|
package eu.eudat.elastic.repository;
|
||
|
|
||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
|
import eu.eudat.elastic.criteria.Criteria;
|
||
|
import eu.eudat.elastic.entities.ElasticEntity;
|
||
|
import org.elasticsearch.client.Client;
|
||
|
import org.elasticsearch.client.RestClient;
|
||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
/**
|
||
|
* Created by ikalyvas on 7/5/2018.
|
||
|
*/
|
||
|
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
|
||
|
private RestHighLevelClient client;
|
||
|
|
||
|
public RestHighLevelClient getClient() {
|
||
|
return client;
|
||
|
}
|
||
|
|
||
|
public ElasticRepository(RestHighLevelClient client) {
|
||
|
this.client = client;
|
||
|
}
|
||
|
|
||
|
public <T> T transformFromString(String value, Class<T> tClass) {
|
||
|
ObjectMapper mapper = new ObjectMapper();
|
||
|
T item = null;
|
||
|
try {
|
||
|
item = mapper.readValue(value, tClass);
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return item;
|
||
|
}
|
||
|
}
|