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.FileWriter;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -126,7 +129,11 @@ public class ExportXmlBuilder {
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() : ""));
} catch (IOException e) {
valueField.setTextContent(field.getValue().toString());
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());
}
}
}
elementField.appendChild(valueField);

View File

@ -20,6 +20,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
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.stream.Collectors;
import java.util.stream.Stream;
@ -152,7 +156,12 @@ public class DatasetRDAMapper {
templateIdsToValues.entrySet().forEach(entry -> {
boolean isFound = foundNodes.stream().anyMatch(node -> node.get("id").asText().equals(entry.getKey()));
if (!isFound && entry.getValue() != null && !entry.getValue().toString().isEmpty()) {
rda.setAdditionalProperty(entry.getKey(), entry.getValue());
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());
}
}
});