Merge branch 'ui-redesign' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot into ui-redesign

This commit is contained in:
gpapavgeri 2020-07-23 16:24:43 +03:00
commit 762f873db1
3 changed files with 45 additions and 22 deletions

View File

@ -23,6 +23,9 @@ public class DatasetMapper {
} }
public Dataset toElastic(eu.eudat.data.entities.Dataset dataset, List<Tag> tags) throws Exception { public Dataset toElastic(eu.eudat.data.entities.Dataset dataset, List<Tag> tags) throws Exception {
if (dataset.getProfile() == null) {
return null;
}
Dataset elastic = new Dataset(); Dataset elastic = new Dataset();
elastic.setId(dataset.getId().toString()); elastic.setId(dataset.getId().toString());
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {

View File

@ -1,9 +1,7 @@
package eu.eudat.logic.mapper.elastic; package eu.eudat.logic.mapper.elastic;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMP;
import eu.eudat.elastic.entities.Collaborator;
import eu.eudat.elastic.entities.Dataset; import eu.eudat.elastic.entities.Dataset;
import eu.eudat.elastic.entities.Dmp; import eu.eudat.elastic.entities.Dmp;
import eu.eudat.elastic.entities.Tag; import eu.eudat.elastic.entities.Tag;
@ -12,10 +10,10 @@ import eu.eudat.logic.services.ApiContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DmpMapper { public class DmpMapper {
@ -70,7 +68,7 @@ public class DmpMapper {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
return null; return null;
}).collect(Collectors.toList())); }).filter(Objects::nonNull).collect(Collectors.toList()));
} }
if (dmp.getAssociatedDmps() != null) { if (dmp.getAssociatedDmps() != null) {
elastic.setTemplates(dmp.getAssociatedDmps().stream().map(DatasetTemplateMapper::toElastic).collect(Collectors.toList())); elastic.setTemplates(dmp.getAssociatedDmps().stream().map(DatasetTemplateMapper::toElastic).collect(Collectors.toList()));

View File

@ -1,6 +1,6 @@
package eu.eudat.logic.utilities.documents.word; package eu.eudat.logic.utilities.documents.word;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.documents.types.ParagraphStyle; import eu.eudat.logic.utilities.documents.types.ParagraphStyle;
@ -13,8 +13,6 @@ import eu.eudat.models.data.user.components.datasetprofile.Section;
import eu.eudat.models.data.user.composite.DatasetProfilePage; import eu.eudat.models.data.user.composite.DatasetProfilePage;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import org.apache.poi.xwpf.usermodel.*; import org.apache.poi.xwpf.usermodel.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
@ -24,9 +22,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
public class WordBuilder { public class WordBuilder {
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class); private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
@ -234,15 +230,33 @@ public class WordBuilder {
String comboboxType = ((ComboBoxData) field.getData()).getType(); String comboboxType = ((ComboBoxData) field.getData()).getType();
if (comboboxType.equals("autocomplete")) { if (comboboxType.equals("autocomplete")) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
if (field.getValue() == null) return null; if (field.getValue() == null) return null;
Map<String, String> map = new HashMap<>(); List<Map<String, Object>> mapList = new ArrayList<>();
if (!field.getValue().equals("")) { if (!field.getValue().equals("") && field.getValue().toString() != null) {
try { try {
mapList = Arrays.asList(mapper.readValue(field.getValue().toString(), HashMap[].class));
}catch (Exception e) {
logger.warn(e.getMessage(), e);
Map <String, Object> map = new HashMap<>();
map.put("label", field.getValue().toString());
mapList.add(map);
}
/*try {
if (field.getValue().toString().startsWith("[")) {
JSONArray jsonarray = new JSONArray(field.getValue().toString()); JSONArray jsonarray = new JSONArray(field.getValue().toString());
for (int i = 0; i < jsonarray.length(); i++) { for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i); JSONObject jsonObject = jsonarray.getJSONObject(i);
String id = jsonobject.getString("id"); String id = jsonObject.get("id").toString();
String label = jsonobject.getString("label"); String label = jsonObject.getString("label");
if (id != null && label != null) {
map.put(id, label);
}
}
} else if (field.getValue().toString().startsWith("{")) {
JSONObject jsonObject = new JSONObject(field.getValue().toString());
String id = jsonObject.get("id").toString();
String label = jsonObject.getString("label");
if (id != null && label != null) { if (id != null && label != null) {
map.put(id, label); map.put(id, label);
} }
@ -251,13 +265,21 @@ public class WordBuilder {
Map<String, String> exMap = mapper.readValue(field.getValue().toString(), new TypeReference<Map<String, String>>() { Map<String, String> exMap = mapper.readValue(field.getValue().toString(), new TypeReference<Map<String, String>>() {
}); });
return exMap.get("label"); return exMap.get("label");
} }*/
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int index = 0; int index = 0;
for (Map.Entry<String, String> entry : map.entrySet()) { for (Map<String, Object> map: mapList) {
sb.append(entry.getValue()); if (!map.containsKey("label") && !map.containsKey("description")) {
if (index != map.size() - 1) sb.append(", "); logger.error("Value is missing the \"label\" and the \"description\" attributes");
map.put("label", "unknown Name");
}
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() != null && (entry.getKey().equals("label") || entry.getKey().equals("description"))) {
sb.append(entry.getValue().toString());
}
}
if (index != mapList.size() - 1) sb.append(", ");
index++; index++;
} }
return sb.toString(); return sb.toString();
@ -269,7 +291,7 @@ public class WordBuilder {
if (field.getValue() != null && field.getValue().equals("true")) return "Yes"; if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
else return "No"; else return "No";
case "radiobox": case "radiobox":
return field.getValue().toString(); return field.getValue() != null ? field.getValue().toString() : null;
case "checkBox": case "checkBox":
CheckBoxData data = (CheckBoxData) field.getData(); CheckBoxData data = (CheckBoxData) field.getData();
if (field.getValue() == null || field.getValue().equals("false")) return null; if (field.getValue() == null || field.getValue().equals("false")) return null;