format prefilling fixes
This commit is contained in:
parent
bd5041e4e3
commit
048189952c
|
@ -22,6 +22,11 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import net.minidev.json.JSONValue;
|
import net.minidev.json.JSONValue;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
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.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -29,6 +34,7 @@ import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> {
|
public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel> {
|
||||||
|
@ -371,11 +377,11 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
||||||
}
|
}
|
||||||
for (JsonNode node: nodes) {
|
for (JsonNode node: nodes) {
|
||||||
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText();
|
||||||
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format")){
|
if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.format") && !value.equals("null")){
|
||||||
JSONArray jsonArr = new JSONArray(value);
|
JSONArray jsonArr = new JSONArray(value);
|
||||||
List<String> formats = new ArrayList<>();
|
List<String> formats = new ArrayList<>();
|
||||||
String extension;
|
String extension;
|
||||||
for (int i = 0; i < jsonArr.length(); i++){
|
for(int i = 0; i < jsonArr.length(); i++){
|
||||||
JSONObject jsonObj = jsonArr.getJSONObject(i);
|
JSONObject jsonObj = jsonArr.getJSONObject(i);
|
||||||
String filename = (String) jsonObj.get("filename");
|
String filename = (String) jsonObj.get("filename");
|
||||||
int index = filename.lastIndexOf('.');
|
int index = filename.lastIndexOf('.');
|
||||||
|
@ -383,8 +389,37 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
|
||||||
formats.add(extension);
|
formats.add(extension);
|
||||||
}
|
}
|
||||||
formats = formats.stream().distinct().collect(Collectors.toList());
|
formats = formats.stream().distinct().collect(Collectors.toList());
|
||||||
String format = String.join(", ", formats);
|
List<Object> standardFormats = new ArrayList<>();
|
||||||
properties.put(id, format);
|
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")));
|
||||||
|
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)){
|
||||||
|
JSONObject cur = new JSONObject();
|
||||||
|
cur.put("label", formatName.toString());
|
||||||
|
standardFormats.add(cur.toString());
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(found){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
properties.put(id, standardFormats);
|
||||||
}
|
}
|
||||||
else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
|
||||||
value = value.replace("\"", "");
|
value = value.replace("\"", "");
|
||||||
|
|
|
@ -1040,6 +1040,7 @@
|
||||||
<mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/>
|
<mapping source="metadata.access_right" maDmpTarget="dataset.distribution.data_access"/>
|
||||||
<mapping source="metadata.publication_date" maDmpTarget="dataset.issued"/>
|
<mapping source="metadata.publication_date" maDmpTarget="dataset.issued"/>
|
||||||
<mapping source="metadata.license.created" maDmpTarget="dataset.distribution.license.start_date"/>
|
<mapping source="metadata.license.created" maDmpTarget="dataset.distribution.license.start_date"/>
|
||||||
|
<mapping source="metadata.embargo_date" maDmpTarget="dataset.distribution.license.start_date"/>
|
||||||
<mapping source="files" maDmpTarget="dataset.distribution.format"/>
|
<mapping source="files" maDmpTarget="dataset.distribution.format"/>
|
||||||
</mappings>
|
</mappings>
|
||||||
<fixedMappings>
|
<fixedMappings>
|
||||||
|
|
Loading…
Reference in New Issue