no message
parent
efb7af10b5
commit
78b91ee3e0
@ -1,6 +1,6 @@
|
||||
TAG=6.2.1
|
||||
ENV=dev
|
||||
TAG=6.3.0
|
||||
ENV=prod
|
||||
PROFILE=production
|
||||
AOT=no-aot
|
||||
ELASTIC_VERSION=6.2.1
|
||||
AOT=aot
|
||||
ELASTIC_VERSION=6.3.0
|
||||
ELASTIC_PASSWORD=changeme
|
||||
|
@ -1,3 +1,3 @@
|
||||
TAG=6.2.1
|
||||
ELASTIC_VERSION=6.2.1
|
||||
TAG=6.3.1
|
||||
ELASTIC_VERSION=6.3.1
|
||||
ELASTIC_PASSWORD=changeme
|
||||
|
@ -1,5 +1,11 @@
|
||||
FROM openjdk:8-jdk-alpine
|
||||
RUN apk add --update \
|
||||
curl \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
VOLUME /tmp
|
||||
ARG PROFILE=dev
|
||||
ARG PROFILE=production
|
||||
ENV PROF $PROFILE
|
||||
ADD web/src/main/resources/ProjectConfiguration.xml /tmp/ProjectConfiguration.xml
|
||||
ADD web/src/main/resources/ExternalUrls.xml /tmp/ExternalUrls.xml
|
||||
ADD web/target/web-1.0-SNAPSHOT.jar app.jar
|
||||
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=${PROFILE}","-jar","/app.jar"]
|
||||
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom" ,"-Dspring.profiles.active=${PROF}","-jar","/app.jar"]
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>dmp-backend</artifactId>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>elastic</artifactId>
|
||||
|
||||
</project>
|
@ -0,0 +1,7 @@
|
||||
package eu.eudat.elastic.criteria;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public abstract class Criteria {
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package eu.eudat.elastic.criteria;
|
||||
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class DatasetCriteria extends Criteria {
|
||||
public List<Tag> tags;
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package eu.eudat.elastic.criteria;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class TagCriteria extends Criteria {
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package eu.eudat.elastic.entities;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class Dataset implements ElasticEntity<Dataset> {
|
||||
|
||||
private String id;
|
||||
private List<Tag> tags = new LinkedList<>();
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("id", this.id);
|
||||
builder.startArray("tags");
|
||||
this.tags.forEach(x -> {
|
||||
try {
|
||||
x.toElasticEntity(builder);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
builder.endArray();
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset fromElasticEntity(Map<String, Object> fields) {
|
||||
if (fields != null) {
|
||||
this.id = (String) fields.get("id");
|
||||
this.tags = ((List<Tag>) fields.get("tags"));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package eu.eudat.elastic.entities;
|
||||
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface ElasticEntity<T> {
|
||||
XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException;
|
||||
T fromElasticEntity(Map<String, Object> fields);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package eu.eudat.elastic.entities;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class Tag implements ElasticEntity {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field("id", this.id);
|
||||
builder.field("name", this.name);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromElasticEntity(Map fields) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package eu.eudat.elastic.repository;
|
||||
|
||||
import eu.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
@Service("datasetRepository")
|
||||
public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteria> {
|
||||
|
||||
@Autowired
|
||||
public DatasetRepository(RestHighLevelClient client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset createOrUpdate(Dataset entity) throws IOException {
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
IndexRequest request = new IndexRequest("datasets", "doc", entity.getId()).source(entity.toElasticEntity(builder));
|
||||
this.getClient().index(request);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset findDocument(String id) throws IOException {
|
||||
GetRequest request = new GetRequest("datasets","doc",id);
|
||||
GetResponse response = this.getClient().get(request);
|
||||
return new Dataset().fromElasticEntity(response.getSourceAsMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dataset> query(DatasetCriteria criteria) throws ExecutionException, InterruptedException, IOException {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
|
||||
.should(QueryBuilders.termsQuery("tags.name.keyword", criteria.getTags().stream().map(x -> x.getName()).collect(Collectors.toList())));
|
||||
searchSourceBuilder.query(boolQuery);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest);
|
||||
return Arrays.stream(response.getHits().getHits()).map(x -> this.transformFromString(x.getSourceAsString(), Dataset.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws IOException {
|
||||
GetIndexRequest request = new GetIndexRequest();
|
||||
request.indices("datasets");
|
||||
return this.getClient().indices().exists(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package eu.eudat.elastic.repository;
|
||||
|
||||
import eu.eudat.elastic.criteria.Criteria;
|
||||
import eu.eudat.elastic.entities.ElasticEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface Repository<ET extends ElasticEntity, C extends Criteria> {
|
||||
|
||||
ET createOrUpdate(ET entity) throws IOException;
|
||||
|
||||
ET findDocument(String id) throws IOException;
|
||||
|
||||
List<ET> query(C criteria) throws ExecutionException, InterruptedException, IOException;
|
||||
|
||||
boolean exists() throws IOException;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>dmp-backend</artifactId>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>query-engine</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<artifactId>data</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
import eu.eudat.data.entities.DataRepository;
|
||||
import eu.eudat.query.engine.builder.QueryBuilder;
|
||||
import eu.eudat.query.engine.builder.QueryBuilderImpl;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class Main {
|
||||
public void Test(){
|
||||
QueryBuilder<DataRepository> queryBuilder = new QueryBuilderImpl<>();
|
||||
queryBuilder.where((entity, comparisonExpression) -> comparisonExpression.field("id").greaterThan(5));
|
||||
//queryBuilder.and(((entity, expression) -> expression.field("id").greaterThan(4)),((entity, expression) -> expression.field("id").greaterThan(5)));
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package eu.eudat.query.engine.builder;
|
||||
|
||||
import eu.eudat.query.engine.expressions.Expression;
|
||||
import eu.eudat.query.engine.predicates.AndPredicate;
|
||||
import eu.eudat.query.engine.predicates.ComparisonPredicate;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface QueryBuilder<T> {
|
||||
|
||||
Expression where(ComparisonPredicate<T> wherePredicate);
|
||||
|
||||
Expression and(AndPredicate<T> andPredicate);
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package eu.eudat.query.engine.builder;
|
||||
|
||||
import eu.eudat.query.engine.expressions.Expression;
|
||||
import eu.eudat.query.engine.predicates.AndPredicate;
|
||||
import eu.eudat.query.engine.predicates.ComparisonPredicate;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class QueryBuilderImpl<T> implements QueryBuilder<T> {
|
||||
|
||||
|
||||
@Override
|
||||
public Expression where(ComparisonPredicate wherePredicate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression and(AndPredicate<T> andPredicate) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.eudat.query.engine.expressions;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public abstract class AbstractFieldExpression<T extends AbstractFieldExpression<T>> {
|
||||
private String field;
|
||||
|
||||
protected String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public T field(String field) {
|
||||
this.field = field;
|
||||
return (T)this;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package eu.eudat.query.engine.expressions;
|
||||
|
||||
import eu.eudat.query.engine.types.expression.comparison.ComparisonExpressionType;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public class ComparisonExpression extends AbstractFieldExpression<ComparisonExpression> implements Expression {
|
||||
|
||||
private ComparisonExpressionType type;
|
||||
private Object value;
|
||||
|
||||
public <T> Expression greaterThan(T value){
|
||||
this.value = value;
|
||||
this.type = ComparisonExpressionType.GREATER_THAN;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Expression greaterThanOrEqual(T value){
|
||||
this.value = value;
|
||||
this.type = ComparisonExpressionType.GREATER_OR_EQUAL_THAN;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Expression equal(T value){
|
||||
this.value = value;
|
||||
this.type = ComparisonExpressionType.EQUAL;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Expression lessThan(T value){
|
||||
this.value = value;
|
||||
this.type = ComparisonExpressionType.LESS_THAN;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> Expression lessOrEqualThan(T value){
|
||||
this.value = value;
|
||||
this.type = ComparisonExpressionType.LESS_OR_EQUAL_THAN;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package eu.eudat.query.engine.expressions;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface Expression {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package eu.eudat.query.engine.predicates;
|
||||
|
||||
import eu.eudat.query.engine.expressions.ComparisonExpression;
|
||||
import eu.eudat.query.engine.expressions.Expression;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface AndPredicate<T> {
|
||||
<E extends Expression> Expression and(ComparisonPredicate<T>... predicates);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package eu.eudat.query.engine.predicates;
|
||||
|
||||
import eu.eudat.query.engine.expressions.ComparisonExpression;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface ComparisonPredicate<T> extends Predicate<T, ComparisonExpression> {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package eu.eudat.query.engine.predicates;
|
||||
|
||||
import eu.eudat.query.engine.expressions.Expression;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public interface Predicate<T,E extends Expression> {
|
||||
Expression where(T entity, E expression);
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package eu.eudat.query.engine.types.expression.comparison;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public enum ComparisonExpressionType {
|
||||
EQUAL, GREATER_THAN, GREATER_OR_EQUAL_THAN, LESS_THAN, LESS_OR_EQUAL_THAN
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package eu.eudat.configurations;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.transport.client.PreBuiltTransportClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
@Configuration
|
||||
public class ElasticSearchConfiguration {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
@Autowired
|
||||
public ElasticSearchConfiguration(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestHighLevelClient client() throws Exception {
|
||||
RestHighLevelClient client = new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost(this.environment.getProperty("elasticsearch.host"),
|
||||
Integer.parseInt(this.environment.getProperty("elasticsearch.port")), "http")));
|
||||
return client;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.elastic.criteria.TagCriteria;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.elastic.repository.Repository;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.external.TagExternalSourcesModel;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api"})
|
||||
public class TagController extends BaseController{
|
||||
|
||||
private Repository<Dataset,TagCriteria> datasetRepository;
|
||||
|
||||
@Autowired
|
||||
public TagController(ApiContext apiContext, Repository tagRepository) {
|
||||
super(apiContext);
|
||||
this.datasetRepository = tagRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/tag/create"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<Dataset>> create(@RequestBody Dataset dataset) {
|
||||
try {
|
||||
Dataset tagEntity = this.datasetRepository.createOrUpdate(dataset);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().payload(dataset).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<TagExternalSourcesModel>> listExternalTagModel(
|
||||
@RequestParam(value = "query", required = false) String query,@RequestParam(value = "type", required = false) String type) {
|
||||
try {
|
||||
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getTags(query,type);
|
||||
TagExternalSourcesModel researchersExternalSourcesModel = new TagExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<TagExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
|
||||
} catch (NoURLFound ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<TagExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
|
||||
} catch (HugeResultSet ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<TagExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
|
||||
} catch (Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<TagExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package eu.eudat.logic.proxy.config.entities;
|
||||
|
||||
import eu.eudat.logic.proxy.config.FetchStrategy;
|
||||
import eu.eudat.logic.proxy.config.UrlConfiguration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 7/9/2018.
|
||||
*/
|
||||
public class TagUrls {
|
||||
List<UrlConfiguration> urls;
|
||||
FetchStrategy fetchMode;
|
||||
|
||||
public List<UrlConfiguration> getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name = "urlConfig")
|
||||
public void setUrls(List<UrlConfiguration> urls) {
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public FetchStrategy getFetchMode() {
|
||||
return fetchMode;
|
||||
}
|
||||
|
||||
@XmlElement(name = "fetchMode")
|
||||
public void setFetchMode(FetchStrategy fetchMode) {
|
||||
this.fetchMode = fetchMode;
|
||||
}
|
||||
}
|