rda export import tag bug, format preffiling fixed
This commit is contained in:
parent
bf77a85acb
commit
da5ba952e1
|
@ -164,6 +164,10 @@ public class DataManagementProfileManager {
|
|||
}
|
||||
|
||||
private List<Tuple<String, String>> externalAutocompleteRequest(DmpProfileExternalAutoComplete data, String like) {
|
||||
return externalAutocompleteRequest(data.getUrl(), data.getOptionsRoot(), data.getLabel(), data.getValue(), like);
|
||||
}
|
||||
|
||||
public static List<Tuple<String, String>> externalAutocompleteRequest(String url, String optionsRoot, String label, String value, String like) {
|
||||
List<Tuple<String, String>> result = new LinkedList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
@ -171,11 +175,12 @@ public class DataManagementProfileManager {
|
|||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
|
||||
|
||||
ResponseEntity<Object> response = restTemplate.exchange(data.getUrl() + "?search=" + like, HttpMethod.GET, entity, Object.class);
|
||||
ResponseEntity<Object> response = restTemplate.exchange(url + "?search=" + like, HttpMethod.GET, entity, Object.class);
|
||||
DocumentContext jsonContext = JsonPath.parse(response.getBody());
|
||||
|
||||
List<Map<String, String>> jsonItems = jsonContext.read(data.getOptionsRoot() + "['" + data.getLabel() + "','" + data.getValue() + "']");
|
||||
jsonItems.forEach(item -> result.add(new Tuple<>(item.get(data.getValue()), item.get(data.getLabel()))));
|
||||
List<Map<String, String>> jsonItems = jsonContext.read(optionsRoot + "['" + label + "','" + value + "']");
|
||||
jsonItems.forEach(item -> result.add(new Tuple<>(item.get(value), item.get(label))));
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1050,10 +1050,13 @@ public class DatasetManager {
|
|||
Set<JsonNode> tagNodes = new HashSet<>();
|
||||
tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "renderStyle", "tags", true));
|
||||
tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "rdaProperty", "dataset.keyword"));
|
||||
if(wizardModel.getTags() == null){
|
||||
wizardModel.setTags(new ArrayList<>());
|
||||
}
|
||||
if (!tagNodes.isEmpty()) {
|
||||
tagNodes.forEach(node -> {
|
||||
JsonNode value = node.get("value");
|
||||
if (!value.toString().equals("\"\"")) {
|
||||
if (!value.toString().equals("\"\"") && !value.toString().equals("null")) {
|
||||
String stringValue = value.toString().replaceAll("=", ":");
|
||||
JSONArray values = new JSONArray(stringValue);
|
||||
values.iterator().forEachRemaining(element -> {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.entities.*;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
import eu.eudat.logic.managers.DataManagementProfileManager;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
import eu.eudat.logic.proxy.config.entities.PrefillingFixedMapping;
|
||||
import eu.eudat.logic.proxy.config.entities.PrefillingGet;
|
||||
|
@ -18,15 +19,11 @@ import eu.eudat.models.data.dataset.Service;
|
|||
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
import net.minidev.json.JSONValue;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -34,7 +31,6 @@ import java.time.LocalDate;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> {
|
||||
|
@ -361,6 +357,11 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
if (rawTags.get(0) instanceof String) {
|
||||
List<Tag> parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList());
|
||||
value = mapper.writeValueAsString(parsedTags);
|
||||
List<JsonNode> nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.keyword");
|
||||
for (JsonNode node: nodes) {
|
||||
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
||||
properties.put(id, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0]));
|
||||
|
@ -375,9 +376,10 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
date = date.plusYears(20);
|
||||
value = date.toString();
|
||||
}
|
||||
StringBuilder freeTextFormat = new StringBuilder();
|
||||
for (JsonNode node: nodes) {
|
||||
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format") && !value.equals("null")){
|
||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format") && !value.equals("null")) {
|
||||
JSONArray jsonArr = new JSONArray(value);
|
||||
List<String> formats = new ArrayList<>();
|
||||
String extension;
|
||||
|
@ -389,53 +391,46 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
|||
formats.add(extension);
|
||||
}
|
||||
formats = formats.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
List<Object> standardFormats = new ArrayList<>();
|
||||
StringBuilder freeTextFormat = new StringBuilder();
|
||||
for(String format: formats) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String parsedUrl = "https://eestore.paas2.uninett.no/api/fileformat/?search=" + format;
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(new MediaType("application", "vnd.api+json")));
|
||||
HttpEntity<String> entity = new HttpEntity("", headers);
|
||||
Map<String, Object> data = restTemplate.exchange(parsedUrl, HttpMethod.GET, entity, LinkedHashMap.class).getBody();
|
||||
jsonArr = new JSONArray(new ObjectMapper().writeValueAsString(data.get("data")));
|
||||
if(jsonArr.length() > 0) {
|
||||
for (int i = 0; i < jsonArr.length(); i++) {
|
||||
JSONObject jsonObj = jsonArr.getJSONObject(i);
|
||||
jsonObj = jsonObj.getJSONObject("attributes");
|
||||
JSONArray extensions = jsonObj.getJSONArray("extensions");
|
||||
Object formatName = jsonObj.get("name");
|
||||
boolean found = false;
|
||||
for (int j = 0; j < extensions.length(); j++) {
|
||||
if (extensions.getString(j).equals(format)) {
|
||||
|
||||
String renderStyle = node.get(0) != null ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText();
|
||||
if(renderStyle.equals("combobox")){
|
||||
String autocomplete = node.get(0) != null ? node.get(0).get("data").get("type").asText() : node.get("data").get("type").asText();
|
||||
if(autocomplete.equals("autocomplete")) {
|
||||
JsonNode urlNode = node.get(0) != null ? node.get(0).get("data").get("autoCompleteSingleDataList") : node.get("data").get("autoCompleteSingleDataList");
|
||||
String url = urlNode.get(0).get("url").asText();
|
||||
String optionsRoot = urlNode.get(0).get("optionsRoot").asText();
|
||||
String label = urlNode.get(0).get("autoCompleteOptions").get("label").asText();
|
||||
String val = urlNode.get(0).get("autoCompleteOptions").get("value").asText();
|
||||
for (String format : formats) {
|
||||
List<Tuple<String, String>> result = DataManagementProfileManager.externalAutocompleteRequest(url, optionsRoot, label, val, format);
|
||||
result = result.stream().distinct().collect(Collectors.toList());
|
||||
if(!result.isEmpty()){
|
||||
for (Tuple<String, String> f : result) {
|
||||
JSONObject cur = new JSONObject();
|
||||
cur.put("label", formatName.toString());
|
||||
cur.put("label", f.getLabel());
|
||||
standardFormats.add(cur.toString());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
freeTextFormat.append(f.getLabel()).append(", ");
|
||||
}
|
||||
}
|
||||
else{
|
||||
freeTextFormat.append(format).append(", ");
|
||||
}
|
||||
|
||||
}
|
||||
String renderStyle = node.get(0) != null ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText();
|
||||
if(renderStyle.equals("freetext")){
|
||||
if (freeTextFormat.length() > 0) {
|
||||
freeTextFormat.setLength(freeTextFormat.length() - 2);
|
||||
}
|
||||
properties.put(id, freeTextFormat.toString());
|
||||
}
|
||||
else{
|
||||
properties.put(id, standardFormats);
|
||||
}
|
||||
}
|
||||
else if(renderStyle.equals("freetext")){
|
||||
if (freeTextFormat.length() == 0) {
|
||||
for (String format : formats) {
|
||||
freeTextFormat.append(format).append(", ");
|
||||
}
|
||||
}
|
||||
freeTextFormat.setLength(freeTextFormat.length() - 2);
|
||||
properties.put(id, freeTextFormat.toString());
|
||||
}
|
||||
}
|
||||
else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
||||
value = value.replace("\"", "");
|
||||
if(value.equals("open")){
|
||||
|
|
|
@ -89,12 +89,12 @@ public class DistributionRDAMapper {
|
|||
int i = 1;
|
||||
while(iter.hasNext()) {
|
||||
JsonNode current = iter.next();
|
||||
String format = JavaToJson.objectStringToJson(current.asText());
|
||||
String format = JavaToJson.objectStringToJson(current.toString());
|
||||
try {
|
||||
Map<String, String> result = new ObjectMapper().readValue(format, HashMap.class);
|
||||
format = result.get("label");
|
||||
formats.add(format);
|
||||
rda.setAdditionalProperty("format" + i++, new ObjectMapper().readTree(current.asText()));
|
||||
rda.setAdditionalProperty("format" + i++, new ObjectMapper().readTree(current.toString()));
|
||||
}
|
||||
catch(JsonProcessingException e){
|
||||
logger.warn(e.getMessage());
|
||||
|
@ -103,8 +103,13 @@ public class DistributionRDAMapper {
|
|||
rda.setFormat(formats);
|
||||
}
|
||||
else{
|
||||
if(rda.getFormat() == null || rda.getFormat().isEmpty()){
|
||||
rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(","))));
|
||||
}
|
||||
else{
|
||||
rda.getFormat().addAll(Arrays.asList(rdaValue.replace(" ", "").split(",")));
|
||||
}
|
||||
}
|
||||
rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText());
|
||||
break;
|
||||
case TITLE:
|
||||
|
@ -209,6 +214,9 @@ public class DistributionRDAMapper {
|
|||
break;
|
||||
case FORMAT:
|
||||
if (rda.getFormat() != null && !rda.getFormat().isEmpty()) {
|
||||
String style = distributionNode.get("viewStyle").get("renderStyle").asText();
|
||||
if(style.equals("combobox")) {
|
||||
if (distributionNode.get("data").get("type").asText().equals("autocomplete")) {
|
||||
Map<String, Object> additionalProperties = rda.getAdditionalProperties();
|
||||
List<Object> standardFormats = new ArrayList<>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -223,6 +231,11 @@ public class DistributionRDAMapper {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else if(style.equals("freetext")){
|
||||
properties.put(distributionNode.get("id").asText(), String.join(", ", rda.getFormat()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LICENSE:
|
||||
if (rda.getLicense() != null && !rda.getLicense().isEmpty()) {
|
||||
|
|
Loading…
Reference in New Issue