Fixed various issues when creating world document and storing data to the elastic
This commit is contained in:
parent
8ffdfdba1f
commit
ac00b01943
|
@ -25,6 +25,9 @@ public class DatasetMapper {
|
|||
}
|
||||
|
||||
public Dataset toElastic(eu.eudat.data.entities.Dataset dataset, List<Tag> tags) throws Exception {
|
||||
if (dataset.getProfile() == null) {
|
||||
return null;
|
||||
}
|
||||
Dataset elastic = new Dataset();
|
||||
elastic.setId(dataset.getId().toString());
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package eu.eudat.logic.mapper.elastic;
|
||||
|
||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
||||
import eu.eudat.data.dao.entities.DMPDao;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.elastic.entities.Collaborator;
|
||||
import eu.eudat.elastic.entities.Dataset;
|
||||
import eu.eudat.elastic.entities.Dmp;
|
||||
import eu.eudat.elastic.entities.Tag;
|
||||
|
@ -12,10 +10,10 @@ import eu.eudat.logic.services.ApiContext;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DmpMapper {
|
||||
|
@ -70,7 +68,7 @@ public class DmpMapper {
|
|||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList()));
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
}
|
||||
if (dmp.getAssociatedDmps() != null) {
|
||||
elastic.setTemplates(dmp.getAssociatedDmps().stream().map(DatasetTemplateMapper::toElastic).collect(Collectors.toList()));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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 eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
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.PagedDatasetProfile;
|
||||
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.CTDecimalNumber;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
|
||||
|
@ -24,9 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class WordBuilder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(WordBuilder.class);
|
||||
|
@ -234,15 +230,33 @@ public class WordBuilder {
|
|||
String comboboxType = ((ComboBoxData) field.getData()).getType();
|
||||
if (comboboxType.equals("autocomplete")) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
if (field.getValue() == null) return null;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (!field.getValue().equals("")) {
|
||||
List<Map<String, Object>> mapList = new ArrayList<>();
|
||||
if (!field.getValue().equals("") && field.getValue().toString() != null) {
|
||||
try {
|
||||
JSONArray jsonarray = new JSONArray(field.getValue().toString());
|
||||
for (int i = 0; i < jsonarray.length(); i++) {
|
||||
JSONObject jsonobject = jsonarray.getJSONObject(i);
|
||||
String id = jsonobject.getString("id");
|
||||
String label = jsonobject.getString("label");
|
||||
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());
|
||||
for (int i = 0; i < jsonarray.length(); i++) {
|
||||
JSONObject jsonObject = jsonarray.getJSONObject(i);
|
||||
String id = jsonObject.get("id").toString();
|
||||
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) {
|
||||
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>>() {
|
||||
});
|
||||
return exMap.get("label");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int index = 0;
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
sb.append(entry.getValue());
|
||||
if (index != map.size() - 1) sb.append(", ");
|
||||
for (Map<String, Object> map: mapList) {
|
||||
if (!map.containsKey("label") && !map.containsKey("description")) {
|
||||
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++;
|
||||
}
|
||||
return sb.toString();
|
||||
|
@ -269,7 +291,7 @@ public class WordBuilder {
|
|||
if (field.getValue() != null && field.getValue().equals("true")) return "Yes";
|
||||
else return "No";
|
||||
case "radiobox":
|
||||
return field.getValue().toString();
|
||||
return field.getValue() != null ? field.getValue().toString() : null;
|
||||
case "checkBox":
|
||||
CheckBoxData data = (CheckBoxData) field.getData();
|
||||
if (field.getValue() == null || field.getValue().equals("false")) return null;
|
||||
|
|
Loading…
Reference in New Issue