Trim out hours from date picker export on xml and json(ref #7185)

This commit is contained in:
George Kalampokis 2021-11-17 11:12:34 +02:00
parent 4da99d6d83
commit 4eb15da95a
2 changed files with 18 additions and 2 deletions

View File

@ -20,6 +20,9 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -126,9 +129,13 @@ public class ExportXmlBuilder {
Map<String, Object> jsonElement = mapper.readValue(field.getValue().toString(), Map.class); Map<String, Object> jsonElement = mapper.readValue(field.getValue().toString(), Map.class);
valueField.setTextContent((jsonElement.get("label") != null ? jsonElement.get("label").toString() : jsonElement.get("name") != null ? jsonElement.get("name").toString() : "")); valueField.setTextContent((jsonElement.get("label") != null ? jsonElement.get("label").toString() : jsonElement.get("name") != null ? jsonElement.get("name").toString() : ""));
} catch (IOException e) { } catch (IOException e) {
try {
valueField.setTextContent(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(Instant.parse(field.getValue().toString())));
} catch (Exception exc) {
valueField.setTextContent(field.getValue().toString()); valueField.setTextContent(field.getValue().toString());
} }
} }
}
elementField.appendChild(valueField); elementField.appendChild(valueField);
} }
elementFields.appendChild(elementField); elementFields.appendChild(elementField);

View File

@ -20,6 +20,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -152,8 +156,13 @@ public class DatasetRDAMapper {
templateIdsToValues.entrySet().forEach(entry -> { templateIdsToValues.entrySet().forEach(entry -> {
boolean isFound = foundNodes.stream().anyMatch(node -> node.get("id").asText().equals(entry.getKey())); boolean isFound = foundNodes.stream().anyMatch(node -> node.get("id").asText().equals(entry.getKey()));
if (!isFound && entry.getValue() != null && !entry.getValue().toString().isEmpty()) { if (!isFound && entry.getValue() != null && !entry.getValue().toString().isEmpty()) {
try {
Instant time = Instant.parse(entry.getValue().toString());
rda.setAdditionalProperty(entry.getKey(), DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(time));
} catch (DateTimeParseException e) {
rda.setAdditionalProperty(entry.getKey(), entry.getValue()); rda.setAdditionalProperty(entry.getKey(), entry.getValue());
} }
}
}); });