2020-06-08 17:31:34 +02:00
|
|
|
package eu.eudat.models.rda.mapper;
|
|
|
|
|
2021-12-17 11:59:10 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
2020-06-08 17:31:34 +02:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2022-01-28 13:55:52 +01:00
|
|
|
import eu.eudat.elastic.entities.Dataset;
|
2020-09-15 12:21:22 +02:00
|
|
|
import eu.eudat.elastic.entities.Tag;
|
2022-01-28 13:55:52 +01:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2020-09-15 12:21:22 +02:00
|
|
|
import eu.eudat.logic.utilities.json.JavaToJson;
|
2020-06-08 17:31:34 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2020-09-15 12:21:22 +02:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
2020-06-08 17:31:34 +02:00
|
|
|
|
|
|
|
public class KeywordRDAMapper {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
|
|
|
|
|
2020-09-15 12:21:22 +02:00
|
|
|
public static List<String> toRDA(String value) {
|
2022-01-28 13:55:52 +01:00
|
|
|
if (!value.isEmpty() && !value.equals("null")) {
|
2022-01-12 13:10:00 +01:00
|
|
|
try {
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
String valueJson = JavaToJson.objectStringToJson(value);
|
2022-01-28 13:55:52 +01:00
|
|
|
Tag tag = mapper.readValue(valueJson, Tag.class);
|
|
|
|
return new ArrayList<>(Collections.singletonList(tag.getName()));
|
2022-01-12 13:10:00 +01:00
|
|
|
} catch (JsonProcessingException e) {
|
2022-01-28 13:55:52 +01:00
|
|
|
logger.warn(e.getMessage() + ". Attempting to parse it as a String since its a new tag.");
|
|
|
|
return new ArrayList<>(Collections.singletonList(value));
|
2021-10-13 16:47:50 +02:00
|
|
|
}
|
2022-01-12 13:10:00 +01:00
|
|
|
}
|
2020-06-08 17:31:34 +02:00
|
|
|
|
2020-09-15 12:21:22 +02:00
|
|
|
return new ArrayList<>();
|
2020-06-08 17:31:34 +02:00
|
|
|
}
|
|
|
|
}
|