Skip to content

Commit 2afbd3a

Browse files
committed
bugs #15483 fix(resip): date time type editor update handling
1 parent 7d39724 commit 2afbd3a

File tree

2 files changed

+107
-40
lines changed

2 files changed

+107
-40
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pipeline {
55

66
environment {
77
MVN_BASE = "/usr/local/maven/bin/mvn"
8-
MVN_COMMAND = "${MVN_BASE} --settings ${pwd()}/.ci/settings.xml --show-version --batch-mode --errors --fail-at-end -DinstallAtEnd=true -DdeployAtEnd=true "
8+
MVN_COMMAND = "${MVN_BASE} --settings ${pwd()}/.ci/settings.xml --show-version --batch-mode --errors --fail-at-end -DinstallAtEnd=true -DdeployAtEnd=true -Duser.timezone=Europe/Paris"
99
DEPLOY_GOAL = " " // Deploy goal used by maven ; typically "deploy" for master* branches & "" (nothing) for everything else (we don't deploy) ; keep a space so can work in other branches than develop
1010
CI = credentials("app-jenkins")
1111
SERVICE_SONAR_URL = credentials("service-sonar-url")

resip/src/main/java/fr/gouv/vitam/tools/resip/sedaobjecteditor/DateTimeTypeEditor.java

Lines changed: 106 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@
3434
import fr.gouv.vitam.tools.sedalib.metadata.namedtype.DateTimeType;
3535
import fr.gouv.vitam.tools.sedalib.utils.SEDALibException;
3636

37-
import javax.swing.*;
38-
import java.awt.*;
37+
import javax.swing.JLabel;
38+
import javax.swing.JPanel;
39+
import java.awt.Color;
40+
import java.awt.GridBagConstraints;
41+
import java.awt.GridBagLayout;
42+
import java.awt.Insets;
3943
import java.time.LocalDateTime;
40-
import java.time.format.DateTimeFormatter;
44+
import java.time.OffsetDateTime;
45+
import java.time.temporal.TemporalAccessor;
46+
47+
import fr.gouv.vitam.tools.sedalib.metadata.namedtype.DateTimeType.DateTimeFormatType;
4148

4249
/**
4350
* The DateTimeType object editor class.
@@ -47,34 +54,87 @@ public class DateTimeTypeEditor extends SEDAObjectEditor {
4754
/**
4855
* The editedObject edition graphic component
4956
*/
50-
private DateTimePicker valueDateTimePicker;
57+
private final DateTimePicker valueDateTimePicker = new DateTimePicker();
58+
private final JLabel warningLabel = new JLabel();
59+
private DateTimeType lastDateTimeType;
5160

5261
/**
5362
* Instantiates a new DateTimeType editor.
5463
*
5564
* @param metadata the DateTimeType editedObject
56-
* @param father the father
65+
* @param parent the parent editor
5766
* @throws SEDALibException if not a DateTimeType editedObject
5867
*/
59-
public DateTimeTypeEditor(SEDAMetadata metadata, SEDAObjectEditor father) throws SEDALibException {
60-
super(metadata, father);
68+
public DateTimeTypeEditor(SEDAMetadata metadata, SEDAObjectEditor parent) throws SEDALibException {
69+
super(metadata, parent);
70+
6171
if (!(metadata instanceof DateTimeType))
6272
throw new SEDALibException("La métadonnée à éditer n'est pas du bon type");
73+
74+
this.update(getInitialValue());
75+
76+
valueDateTimePicker.setDateTimePermissive(getInitialValue().toLocalDateTime());
77+
valueDateTimePicker.addDateTimeChangeListener((event) -> {
78+
LocalDateTime old = event.getOldDateTimePermissive();
79+
LocalDateTime next = event.getNewDateTimePermissive();
80+
81+
if (next != null && !next.equals(old)) {
82+
update(new DateTimeType(getInitialValue().getXmlElementName(), next));
83+
}
84+
});
85+
86+
JPanel labelPanel = new JPanel();
87+
GridBagLayout gbl = new GridBagLayout();
88+
gbl.columnWeights = new double[] { 1.0 };
89+
labelPanel.setLayout(gbl);
90+
91+
JLabel label = new JLabel(getName() + " :");
92+
label.setToolTipText(getTag());
93+
label.setFont(SEDAObjectEditor.LABEL_FONT);
94+
GridBagConstraints gbc = new GridBagConstraints();
95+
gbc.anchor = GridBagConstraints.LINE_END;
96+
gbc.insets = new Insets(0, 5, 0, 0);
97+
gbc.gridx = 0;
98+
gbc.gridy = 0;
99+
labelPanel.add(label, gbc);
100+
101+
JPanel editPanel = new JPanel();
102+
gbl = new GridBagLayout();
103+
gbl.columnWeights = new double[] { 1.0 };
104+
editPanel.setLayout(gbl);
105+
106+
gbc = new GridBagConstraints();
107+
gbc.insets = new Insets(0, 0, 0, 0);
108+
gbc.anchor = GridBagConstraints.LINE_START;
109+
gbc.gridx = 0;
110+
gbc.gridy = 0;
111+
editPanel.add(valueDateTimePicker, gbc);
112+
113+
gbc = new GridBagConstraints();
114+
gbc.insets = new Insets(0, 0, 0, 0);
115+
gbc.anchor = GridBagConstraints.LINE_START;
116+
gbc.gridx = 0;
117+
gbc.gridy = 1;
118+
editPanel.add(warningLabel, gbc);
119+
120+
this.sedaObjectEditorPanel = new SEDAObjectEditorSimplePanel(this, labelPanel, editPanel);
63121
}
64122

65-
private DateTimeType getDateTimeTypeMetadata() {
123+
private DateTimeType getInitialValue() {
66124
return (DateTimeType) editedObject;
67125
}
68126

69127
/**
70128
* Gets DateTimeType sample.
71129
*
72130
* @param elementName the element name, corresponding to the XML tag in SEDA
73-
* @param minimal the minimal flag, if true subfields are selected and values are empty, if false all subfields are added and values are default values
131+
* @param minimal the minimal flag, if true subfields are selected and
132+
* values are empty, if false all subfields are added and
133+
* values are default values
74134
* @return the seda editedObject sample
75135
* @throws SEDALibException the seda lib exception
76136
*/
77-
static public SEDAMetadata getSEDAMetadataSample(String elementName, boolean minimal) throws SEDALibException {
137+
public static SEDAMetadata getSEDAMetadataSample(String elementName, boolean minimal) throws SEDALibException {
78138
if (minimal)
79139
return new DateTimeType(elementName);
80140
else
@@ -83,9 +143,7 @@ static public SEDAMetadata getSEDAMetadataSample(String elementName, boolean min
83143

84144
@Override
85145
public SEDAMetadata extractEditedObject() throws SEDALibException {
86-
getDateTimeTypeMetadata().setDateTimeString(valueDateTimePicker.getDateTimePermissive().format(
87-
DateTimeFormatter.ISO_LOCAL_DATE_TIME));
88-
return getDateTimeTypeMetadata();
146+
return lastDateTimeType;
89147
}
90148

91149
@Override
@@ -98,35 +156,44 @@ public String getSummary() throws SEDALibException {
98156

99157
@Override
100158
public void createSEDAObjectEditorPanel() throws SEDALibException {
101-
JPanel labelPanel = new JPanel();
102-
GridBagLayout gbl = new GridBagLayout();
103-
gbl.columnWeights = new double[]{1.0};
104-
labelPanel.setLayout(gbl);
105159

106-
JLabel label = new JLabel(getName() + " :");
107-
label.setToolTipText(getTag());
108-
label.setFont(SEDAObjectEditor.LABEL_FONT);
109-
GridBagConstraints gbc = new GridBagConstraints();
110-
gbc.anchor = GridBagConstraints.LINE_END;
111-
gbc.insets = new Insets(0, 5, 0, 0);
112-
gbc.gridx = 0;
113-
gbc.gridy = 0;
114-
labelPanel.add(label, gbc);
160+
}
115161

116-
JPanel editPanel = new JPanel();
117-
gbl = new GridBagLayout();
118-
gbl.columnWeights = new double[]{1.0};
119-
editPanel.setLayout(gbl);
162+
private String computeWarningMessage(DateTimeType dateTimeType) {
163+
String warning = "";
164+
if (dateTimeType.getFormatTypeEnum() == DateTimeFormatType.OFFSET_DATE_TIME)
165+
warning += " (Timezone)";
166+
TemporalAccessor ta = dateTimeType.getTemporalValue();
167+
if (ta instanceof LocalDateTime) {
168+
LocalDateTime ldt = (LocalDateTime) ta;
169+
if (ldt.getSecond() != 0 || ldt.getNano() != 0)
170+
warning += " (Secondes/Millisecondes)";
171+
} else if (ta instanceof OffsetDateTime) {
172+
OffsetDateTime odt = (OffsetDateTime) ta;
173+
if (odt.getSecond() != 0 || odt.getNano() != 0)
174+
warning += " (Secondes/Millisecondes)";
175+
}
120176

121-
valueDateTimePicker = new DateTimePicker();
122-
valueDateTimePicker.setDateTimePermissive(getDateTimeTypeMetadata().toLocalDateTime());
123-
gbc = new GridBagConstraints();
124-
gbc.insets = new Insets(0, 0, 0, 0);
125-
gbc.anchor = GridBagConstraints.LINE_START;
126-
gbc.gridx = 0;
127-
gbc.gridy = 0;
128-
editPanel.add(valueDateTimePicker, gbc);
177+
if (!warning.isEmpty()) {
178+
return "Perte si édition en mode structuré: " + warning;
179+
}
129180

130-
this.sedaObjectEditorPanel = new SEDAObjectEditorSimplePanel(this, labelPanel, editPanel);
181+
return "";
182+
}
183+
184+
private String computeWarningTooltip() {
185+
return "Afin de ne pas perdre d'information, \n" +
186+
"il est nécessaire de modifier les dates en mode non structuré.";
187+
}
188+
189+
private void updateWarning(DateTimeType dateTimeType) {
190+
warningLabel.setText(computeWarningMessage(dateTimeType));
191+
warningLabel.setForeground(Color.RED);
192+
warningLabel.setToolTipText(computeWarningTooltip());
193+
}
194+
195+
private void update(DateTimeType next) {
196+
this.lastDateTimeType = next;
197+
this.updateWarning(this.lastDateTimeType);
131198
}
132199
}

0 commit comments

Comments
 (0)