#7911 - read pid and pid type from external api respones so as to save those values in the dataset field

This commit is contained in:
Bernaldo Mihasi 2023-05-17 13:45:12 +03:00
parent b435994c51
commit af8fddb89c
7 changed files with 112 additions and 6 deletions

View File

@ -8,6 +8,8 @@ import javax.xml.bind.annotation.XmlElement;
public class DataFieldsUrlConfiguration { public class DataFieldsUrlConfiguration {
private String id; private String id;
private String name; private String name;
private String pid;
private String pidTypeField;
private String uri; private String uri;
private String description; private String description;
private String source; private String source;
@ -36,6 +38,23 @@ public class DataFieldsUrlConfiguration {
this.name = name; this.name = name;
} }
public String getPid() {
return pid;
}
@XmlElement(name = "pid")
public void setPid(String pid) {
this.pid = pid;
}
public String getPidTypeField() {
return pidTypeField;
}
@XmlElement(name = "pidTypeField")
public void setPidTypeField(String pidTypeField) {
this.pidTypeField = pidTypeField;
}
public String getUri() { public String getUri() {
return uri; return uri;

View File

@ -467,7 +467,14 @@ public class RemoteFetcher {
} }
private String transformKey(DataUrlConfiguration dataUrlConfiguration, String key) { private String transformKey(DataUrlConfiguration dataUrlConfiguration, String key) {
if (dataUrlConfiguration.getFieldsUrlConfiguration().getId() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getId().replace("'",""))) return "pid"; if (dataUrlConfiguration.getFieldsUrlConfiguration().getId() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getId().replace("'",""))) {
if(dataUrlConfiguration.getFieldsUrlConfiguration().getPid() == null)
return "pid";
else
return "originalId";
}
if (dataUrlConfiguration.getFieldsUrlConfiguration().getPid() != null && key.equals("pid")) return "pid";
if (dataUrlConfiguration.getFieldsUrlConfiguration().getPidTypeField() != null && key.equals("pidTypeField")) return "pidTypeField";
if (dataUrlConfiguration.getFieldsUrlConfiguration().getDescription() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getDescription().replace("'",""))) return "description"; if (dataUrlConfiguration.getFieldsUrlConfiguration().getDescription() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getDescription().replace("'",""))) return "description";
if (dataUrlConfiguration.getFieldsUrlConfiguration().getUri() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getUri().replace("'",""))) return "uri"; if (dataUrlConfiguration.getFieldsUrlConfiguration().getUri() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getUri().replace("'",""))) return "uri";
if (dataUrlConfiguration.getFieldsUrlConfiguration().getName() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getName().replace("'",""))) return "name"; if (dataUrlConfiguration.getFieldsUrlConfiguration().getName() != null && key.equals(dataUrlConfiguration.getFieldsUrlConfiguration().getName().replace("'",""))) return "name";

View File

@ -1,11 +1,15 @@
package eu.eudat.logic.proxy.fetching; package eu.eudat.logic.proxy.fetching;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider; import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import eu.eudat.logic.proxy.config.DataUrlConfiguration; import eu.eudat.logic.proxy.config.DataUrlConfiguration;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.proxy.fetching.entities.Results; import eu.eudat.logic.proxy.fetching.entities.Results;
import io.swagger.models.auth.In;
import net.minidev.json.JSONArray; import net.minidev.json.JSONArray;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -17,6 +21,7 @@ import java.util.stream.Collectors;
public class RemoteFetcherUtils { public class RemoteFetcherUtils {
private final static Logger logger = LoggerFactory.getLogger(RemoteFetcherUtils.class); private final static Logger logger = LoggerFactory.getLogger(RemoteFetcherUtils.class);
private static final ObjectMapper mapper = new ObjectMapper();
public static Results getFromJson(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) { public static Results getFromJson(DocumentContext jsonContext, DataUrlConfiguration jsonDataPath) {
return new Results(parseData(jsonContext, jsonDataPath), return new Results(parseData(jsonContext, jsonDataPath),
@ -60,11 +65,38 @@ public class RemoteFetcherUtils {
try { try {
String value = ((String) getterMethod.invoke(jsonDataPath.getFieldsUrlConfiguration())); String value = ((String) getterMethod.invoke(jsonDataPath.getFieldsUrlConfiguration()));
if (value != null) { if (value != null) {
if (field.getName().equals("pid") || field.getName().equals("pidTypeField")) {
String pid = null;
Object pidObj = stringObjectMap.get(value.split("\\.")[0]);
if(pidObj != null){
if(pidObj instanceof Map){
pid = ((Map<String, String>) pidObj).get(value.split("\\.")[1]);
}
else if(pidObj instanceof List){
Object o = ((List<Map<String,?>>) pidObj).get(0).get(value.split("\\.")[1]);
if(o instanceof String){
pid = (String)o;
}
else if(o instanceof Integer){
pid = String.valueOf(o);
}
}
}
if(pid != null) {
if ((field.getName().equals("pid"))){
parsedData.get(parsedData.size() - 1).put("pid", pid);
}
else{
parsedData.get(parsedData.size() - 1).put("pidTypeField", pid);
}
}
} else {
value = value.replace("'", ""); value = value.replace("'", "");
if (stringObjectMap.containsKey(value)) { if (stringObjectMap.containsKey(value)) {
parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(stringObjectMap.get(value), (field.getName().equals("types") || field.getName().equals("uri")))); parsedData.get(parsedData.size() - 1).put(field.getName().equals("types") ? "tags" : value, normalizeValue(stringObjectMap.get(value), (field.getName().equals("types") || field.getName().equals("uri"))));
} }
} }
}
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
} }
@ -84,8 +116,16 @@ public class RemoteFetcherUtils {
} else { } else {
for (Object o : jarr) { for (Object o : jarr) {
if ((o instanceof Map) && ((Map) o).containsKey("content")) { if ((o instanceof Map) && ((Map) o).containsKey("content")) {
try {
return ((Map<String, String>) o).get("content"); return ((Map<String, String>) o).get("content");
} }
catch (ClassCastException e){
if(((Map<?, ?>) o).get("content") instanceof Integer) {
return String.valueOf(((Map<?, ?>) o).get("content"));
}
return null;
}
}
} }
} }
} else if (value instanceof Map) { } else if (value instanceof Map) {

View File

@ -9,6 +9,7 @@ import eu.eudat.logic.utilities.builders.XmlBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@ -83,8 +84,24 @@ public class DMPToDepositMapper {
} }
fieldDeposit.setSchematics(schematicsDeposit); fieldDeposit.setSchematics(schematicsDeposit);
String fieldId = schematicsNode.getParentNode().getAttributes().getNamedItem("id").getNodeValue(); String fieldId = schematicsNode.getParentNode().getAttributes().getNamedItem("id").getNodeValue();
String value = (String) datasetAnswers.get(fieldId); Object value = datasetAnswers.get(fieldId);
fieldDeposit.setValue(value); fieldDeposit.setValue(value);
Element field = (Element) schematicsNode.getParentNode();
Element viewStyle = (Element) field.getElementsByTagName("viewStyle").item(0);
String renderStyle = viewStyle.getAttribute("renderstyle");
fieldDeposit.setRenderStyleType(renderStyle);
Element data = (Element) field.getElementsByTagName("data").item(0);
String multipleSelection = data.getAttribute("multiList");
String multipleAutoComplete = data.getAttribute("multiAutoComplete");
if(!multipleSelection.isEmpty()){
fieldDeposit.setMultiple(Boolean.parseBoolean(multipleSelection));
}
else if(!multipleAutoComplete.isEmpty()){
fieldDeposit.setMultiple(Boolean.parseBoolean(multipleAutoComplete));
}
else{
fieldDeposit.setMultiple(false);
}
deposit.add(fieldDeposit); deposit.add(fieldDeposit);
} }
} }

View File

@ -18,6 +18,7 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset, E
private String info; private String info;
private ExternalDatasetType type; private ExternalDatasetType type;
private String pid; private String pid;
private String pidTypeField;
private String uri; private String uri;
private String tag; // Api fetching the data private String tag; // Api fetching the data
private String source; // Actual harvested source private String source; // Actual harvested source
@ -85,6 +86,13 @@ public class ExternalDatasetListingModel implements DataModel<ExternalDataset, E
this.pid = pid; this.pid = pid;
} }
public String getPidTypeField() {
return pidTypeField;
}
public void setPidTypeField(String pidTypeField) {
this.pidTypeField = pidTypeField;
}
public String getUri() { public String getUri() {
return uri; return uri;
} }

View File

@ -14,6 +14,7 @@ public class PublicationModel implements DataModel<DataRepository, PublicationMo
private List<String> ids; private List<String> ids;
private String name; private String name;
private String pid; private String pid;
private String pidTypeField;
private String abbreviation; private String abbreviation;
private String uri; private String uri;
private Date created; private Date created;
@ -100,6 +101,14 @@ public class PublicationModel implements DataModel<DataRepository, PublicationMo
this.pid = pid; this.pid = pid;
} }
public String getPidTypeField() {
return pidTypeField;
}
public void setPidTypeField(String pidTypeField) {
this.pidTypeField = pidTypeField;
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -772,6 +772,8 @@ but not
<path>$['results'][*]['result']['metadata']['oaf:entity']['oaf:result']</path> <path>$['results'][*]['result']['metadata']['oaf:entity']['oaf:result']</path>
<fields> <fields>
<id>'originalId'</id> <id>'originalId'</id>
<pid>pid.content</pid>
<pidTypeField>pid.classid</pidTypeField>
<name>'title'</name> <name>'title'</name>
<count>'count'</count> <count>'count'</count>
</fields> </fields>
@ -1017,6 +1019,8 @@ but not
<path>$['results'][*]['result']['metadata']['oaf:entity']['oaf:organization']</path> <path>$['results'][*]['result']['metadata']['oaf:entity']['oaf:organization']</path>
<fields> <fields>
<id>'originalId'</id> <id>'originalId'</id>
<pid>pid.content</pid>
<pidTypeField>pid.classid</pidTypeField>
<name>'legalname'</name> <name>'legalname'</name>
<count>'count'</count> <count>'count'</count>
</fields> </fields>
@ -1098,6 +1102,8 @@ but not
<fields> <fields>
<id>'originalId'</id> <id>'originalId'</id>
<name>'title'</name> <name>'title'</name>
<pid>pid.content</pid>
<pidTypeField>pid.classid</pidTypeField>
<count>'count'</count> <count>'count'</count>
</fields> </fields>
</data> </data>