fix freetext-format bug in prefilling temporarily

This commit is contained in:
Bernaldo Mihasi 2022-02-11 13:09:29 +02:00
parent 26e10b1299
commit eedcf0dfb0
1 changed files with 31 additions and 16 deletions

View File

@ -390,6 +390,7 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
}
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;
@ -398,28 +399,42 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
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;
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)) {
JSONObject cur = new JSONObject();
cur.put("label", formatName.toString());
standardFormats.add(cur.toString());
found = true;
break;
}
}
if (found) {
break;
}
}
if(found){
break;
}
}
else{
freeTextFormat.append(format).append(", ");
}
}
properties.put(id, standardFormats);
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(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){
value = value.replace("\"", "");