37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package eu.eudat.models.rda.mapper;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import eu.eudat.elastic.entities.Tag;
|
|
import eu.eudat.logic.utilities.json.JavaToJson;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class KeywordRDAMapper {
|
|
private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class);
|
|
|
|
public static List<String> toRDA(String value) {
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
value = JavaToJson.objectStringToJson(value);
|
|
if (!value.isEmpty()) {
|
|
try {
|
|
List<Tag> tags = Arrays.asList(mapper.readValue(value, Tag[].class));
|
|
List<String> keywordNames = tags.stream().map(Tag::getName).collect(Collectors.toList());
|
|
return keywordNames;
|
|
} catch (JsonProcessingException e) {
|
|
logger.warn(e.getMessage() + ". Attempting to parse it as a String list.");
|
|
if(!value.isEmpty()) {
|
|
return new ArrayList<>(Arrays.asList(value.replace(" ", "").split(",")));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return new ArrayList<>();
|
|
}
|
|
}
|