45 lines
1.5 KiB
Java
45 lines
1.5 KiB
Java
package eu.eudat.models.rda.mapper;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import eu.eudat.models.rda.Metadatum;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
|
|
public class MetadataRDAMapper {
|
|
private static final Logger logger = LoggerFactory.getLogger(MetadataRDAMapper.class);
|
|
|
|
public static Metadatum toRDA(JsonNode structure, JsonNode properties) {
|
|
Metadatum rda = new Metadatum();
|
|
JsonNode dataNode = null;
|
|
String rdaProperty = structure.get("rdaProperty").asText();
|
|
if (rdaProperty.contains("metadata_standard_id")) {
|
|
try {
|
|
String jsonText = properties.get(structure.get("id").asText()).asText();
|
|
if (jsonText != null && !jsonText.isEmpty()) {
|
|
dataNode = new ObjectMapper().readTree(jsonText);
|
|
for (Iterator<JsonNode> it = dataNode.elements(); it.hasNext(); ) {
|
|
JsonNode data = it.next();
|
|
if (data.get("uri") != null) {
|
|
rda.setMetadataStandardId(MetadataStandardIdRDAMapper.toRDA(data.get("uri").asText()));
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
logger.error(e.getMessage(), e);
|
|
}
|
|
} else if (rdaProperty.contains("description")) {
|
|
rda.setDescription(properties.get(structure.get("id").asText()).asText());
|
|
} else if (rdaProperty.contains("language")) {
|
|
String language = properties.get(structure.get("id").asText()).asText();
|
|
Metadatum.Language lang = Metadatum.Language.fromValue(language);
|
|
rda.setLanguage(lang);
|
|
}
|
|
|
|
return rda;
|
|
}
|
|
}
|