Skip to content

Commit c8354cb

Browse files
committed
story #15307 refactor: remove thread logging duplicated code
1 parent 29e4be0 commit c8354cb

16 files changed

Lines changed: 120 additions & 345 deletions

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/AddThread.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public AddThread(Work work, DataObjectPackageTreeNode targetNode, List<File> fil
128128
this.inOutDialog = dialog;
129129
this.summary = null;
130130
this.exitThrowable = null;
131+
this.spl = new ThreadLoggerFactory(
132+
inOutDialog.extProgressTextArea,
133+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
134+
).getLogger();
131135
dialog.setThread(this);
132136
}
133137

@@ -152,30 +156,7 @@ public String doInBackground() {
152156
}
153157
inOutDialog.extProgressTextArea.setText("Import par glisser/déposer de fichiers\n");
154158
ResipGraphicApp.getTheApp().addThreadRunning = true;
155-
spl = null;
156159
try {
157-
int localLogLevel;
158-
int localLogStep;
159-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
160-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
161-
localLogStep = 1;
162-
} else {
163-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
164-
localLogStep = 1;
165-
}
166-
spl = new SEDALibProgressLogger(
167-
ResipLogger.getGlobalLogger().getLogger(),
168-
localLogLevel,
169-
(count, log) -> {
170-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
171-
inOutDialog.extProgressTextArea.setText(newLog);
172-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
173-
},
174-
localLogStep,
175-
2,
176-
SEDALibProgressLogger.OBJECTS_GROUP,
177-
1000
178-
);
179160
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
180161

181162
DiskImportContext dic;

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/ChangeSeda2VersionThread.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import fr.gouv.vitam.tools.resip.data.Work;
4242
import fr.gouv.vitam.tools.resip.frame.InOutDialog;
4343
import fr.gouv.vitam.tools.resip.utils.ResipException;
44-
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
4544
import fr.gouv.vitam.tools.sedalib.core.DataObjectPackage;
4645
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
4746
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersionConverter;
@@ -88,36 +87,17 @@ public ChangeSeda2VersionThread(
8887
this.dop = dop;
8988
this.inOutDialog = dialog;
9089
this.exitThrowable = null;
91-
this.spl = null;
90+
this.spl = new ThreadLoggerFactory(
91+
inOutDialog.extProgressTextArea,
92+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
93+
).getLogger();
9294
dialog.setThread(this);
9395
}
9496

9597
@Override
9698
public String doInBackground() {
9799
Work work = ResipGraphicApp.getTheApp().currentWork;
98100
try {
99-
int localLogLevel;
100-
int localLogStep;
101-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
102-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
103-
localLogStep = 1;
104-
} else {
105-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
106-
localLogStep = 1000;
107-
}
108-
spl = new SEDALibProgressLogger(
109-
ResipLogger.getGlobalLogger().getLogger(),
110-
localLogLevel,
111-
(count, log) -> {
112-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
113-
inOutDialog.extProgressTextArea.setText(newLog);
114-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
115-
},
116-
localLogStep,
117-
2,
118-
SEDALibProgressLogger.OBJECTS_GROUP,
119-
1000
120-
);
121101
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
122102

123103
if (work == null) throw new ResipException("Pas de contenu à transformer");

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/CheckEndDateThread.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import fr.gouv.vitam.tools.resip.frame.InOutDialog;
4343
import fr.gouv.vitam.tools.resip.frame.VerifyDateDialog;
4444
import fr.gouv.vitam.tools.resip.utils.ResipException;
45-
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
4645
import fr.gouv.vitam.tools.sedalib.core.ArchiveUnit;
4746
import fr.gouv.vitam.tools.sedalib.utils.SEDALibProgressLogger;
4847
import org.joda.time.format.ISODateTimeFormat;
@@ -74,7 +73,10 @@ public CheckEndDateThread(VerifyDateDialog dialog) {
7473
//input
7574
this.verifyDateDialog = dialog;
7675
this.exitThrowable = null;
77-
this.spl = null;
76+
this.spl = new ThreadLoggerFactory(
77+
dialog.getExtProgressTextArea(),
78+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
79+
).getLogger();
7880
}
7981

8082
@Override
@@ -83,27 +85,6 @@ public String doInBackground() {
8385
verifyDateDialog.getExtProgressTextArea().setText("");
8486
Work work = ResipGraphicApp.getTheApp().currentWork;
8587
try {
86-
int localLogLevel, localLogStep;
87-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
88-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
89-
localLogStep = 1;
90-
} else {
91-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
92-
localLogStep = 1000;
93-
}
94-
spl = new SEDALibProgressLogger(
95-
ResipLogger.getGlobalLogger().getLogger(),
96-
localLogLevel,
97-
(count, log) -> {
98-
String newLog = verifyDateDialog.getExtProgressTextArea().getText() + "\n" + log;
99-
verifyDateDialog.getExtProgressTextArea().setText(newLog);
100-
verifyDateDialog.getExtProgressTextArea().setCaretPosition(newLog.length());
101-
},
102-
localLogStep,
103-
2,
104-
SEDALibProgressLogger.OBJECTS_GROUP,
105-
1000
106-
);
10788
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
10889

10990
if (work == null) throw new ResipException("Pas de contenu à valider");

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/CheckProfileThread.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import fr.gouv.vitam.tools.resip.data.Work;
4242
import fr.gouv.vitam.tools.resip.frame.InOutDialog;
4343
import fr.gouv.vitam.tools.resip.utils.ResipException;
44-
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
4544
import fr.gouv.vitam.tools.sedalib.core.ArchiveTransfer;
4645
import fr.gouv.vitam.tools.sedalib.utils.SEDALibProgressLogger;
4746

@@ -73,36 +72,17 @@ public CheckProfileThread(String profileFileName, InOutDialog dialog) {
7372
this.profileFileName = profileFileName;
7473
this.inOutDialog = dialog;
7574
this.exitThrowable = null;
76-
this.spl = null;
75+
this.spl = new ThreadLoggerFactory(
76+
inOutDialog.extProgressTextArea,
77+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
78+
).getLogger();
7779
dialog.setThread(this);
7880
}
7981

8082
@Override
8183
public String doInBackground() {
8284
Work work = ResipGraphicApp.getTheApp().currentWork;
8385
try {
84-
int localLogLevel;
85-
int localLogStep;
86-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
87-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
88-
localLogStep = 1;
89-
} else {
90-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
91-
localLogStep = 1000;
92-
}
93-
spl = new SEDALibProgressLogger(
94-
ResipLogger.getGlobalLogger().getLogger(),
95-
localLogLevel,
96-
(count, log) -> {
97-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
98-
inOutDialog.extProgressTextArea.setText(newLog);
99-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
100-
},
101-
localLogStep,
102-
2,
103-
SEDALibProgressLogger.OBJECTS_GROUP,
104-
1000
105-
);
10686
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
10787

10888
if (work == null) throw new ResipException("Pas de contenu à valider");

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/CleanThread.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
import fr.gouv.vitam.tools.resip.app.ResipGraphicApp;
4141
import fr.gouv.vitam.tools.resip.frame.InOutDialog;
42-
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
4342
import fr.gouv.vitam.tools.sedalib.utils.SEDALibProgressLogger;
4443

4544
import javax.swing.*;
@@ -72,6 +71,10 @@ public CleanThread(String workDir, InOutDialog dialog) {
7271
this.workDir = workDir;
7372
dialog.setThread(this);
7473
this.inOutDialog = dialog;
74+
this.spl = new ThreadLoggerFactory(
75+
inOutDialog.extProgressTextArea,
76+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
77+
).getLogger();
7578
}
7679

7780
private void recursiveDelete(File inFile) throws IOException, InterruptedException {
@@ -87,31 +90,8 @@ private void recursiveDelete(File inFile) throws IOException, InterruptedExcepti
8790

8891
@Override
8992
public String doInBackground() {
90-
spl = null;
9193
fileCounter = 0;
9294
try {
93-
int localLogLevel, localLogStep;
94-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
95-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
96-
localLogStep = 1;
97-
} else {
98-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
99-
localLogStep = 1000;
100-
}
101-
spl = new SEDALibProgressLogger(
102-
ResipLogger.getGlobalLogger().getLogger(),
103-
localLogLevel,
104-
(count, log) -> {
105-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
106-
inOutDialog.extProgressTextArea.setText(newLog);
107-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
108-
},
109-
localLogStep,
110-
2,
111-
SEDALibProgressLogger.OBJECTS_GROUP,
112-
1000
113-
);
114-
11595
doProgressLog(spl, GLOBAL, "Nettoyage du répertoire: " + workDir, null);
11696
for (File f : new File(workDir).listFiles()) {
11797
if (f.isDirectory() && f.toString().endsWith("-tmpdir")) {

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/CompactThread.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public CompactThread(Work work, DataObjectPackageTreeNode targetNode, InOutDialo
116116
this.inOutDialog = dialog;
117117
this.summary = null;
118118
this.exitThrowable = null;
119+
this.spl = new ThreadLoggerFactory(
120+
inOutDialog.extProgressTextArea,
121+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
122+
).getLogger();
119123
dialog.setThread(this);
120124
}
121125

@@ -187,30 +191,7 @@ public String doInBackground() {
187191
}
188192
}
189193
ResipGraphicApp.getTheApp().addThreadRunning = true;
190-
spl = null;
191194
try {
192-
int localLogLevel;
193-
int localLogStep;
194-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
195-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
196-
localLogStep = 1;
197-
} else {
198-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
199-
localLogStep = 1000;
200-
}
201-
spl = new SEDALibProgressLogger(
202-
ResipLogger.getGlobalLogger().getLogger(),
203-
localLogLevel,
204-
(count, log) -> {
205-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
206-
inOutDialog.extProgressTextArea.setText(newLog);
207-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
208-
},
209-
localLogStep,
210-
2,
211-
SEDALibProgressLogger.OBJECTS_GROUP,
212-
1000
213-
);
214195
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
215196

216197
ArchiveUnit targetArchiveUnit = targetNode.getArchiveUnit();

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/DeCompactThread.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public DeCompactThread(Work work, DataObjectPackageTreeNode targetNode, InOutDia
118118
this.inOutDialog = dialog;
119119
this.summary = null;
120120
this.exitThrowable = null;
121+
this.spl = new ThreadLoggerFactory(
122+
inOutDialog.extProgressTextArea,
123+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
124+
).getLogger();
121125
dialog.setThread(this);
122126
}
123127

@@ -189,30 +193,7 @@ public String doInBackground() {
189193
}
190194
}
191195
ResipGraphicApp.getTheApp().addThreadRunning = true;
192-
spl = null;
193196
try {
194-
int localLogLevel;
195-
int localLogStep;
196-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
197-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
198-
localLogStep = 1;
199-
} else {
200-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
201-
localLogStep = 1000;
202-
}
203-
spl = new SEDALibProgressLogger(
204-
ResipLogger.getGlobalLogger().getLogger(),
205-
localLogLevel,
206-
(count, log) -> {
207-
String newLog = inOutDialog.extProgressTextArea.getText() + "\n" + log;
208-
inOutDialog.extProgressTextArea.setText(newLog);
209-
inOutDialog.extProgressTextArea.setCaretPosition(newLog.length());
210-
},
211-
localLogStep,
212-
2,
213-
SEDALibProgressLogger.OBJECTS_GROUP,
214-
1000
215-
);
216197
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
217198

218199
ArchiveUnit targetArchiveUnit = targetNode.getArchiveUnit();

resip/src/main/java/fr/gouv/vitam/tools/resip/threads/DuplicatesThread.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
import fr.gouv.vitam.tools.resip.app.ResipGraphicApp;
4141
import fr.gouv.vitam.tools.resip.frame.DuplicatesWindow;
42-
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
4342
import fr.gouv.vitam.tools.sedalib.core.*;
4443
import fr.gouv.vitam.tools.sedalib.metadata.data.FileInfo;
4544
import fr.gouv.vitam.tools.sedalib.metadata.namedtype.DigestType;
@@ -102,6 +101,10 @@ public DuplicatesThread(
102101
this.binaryHash = binaryHash;
103102
this.binaryFilename = binaryFilename;
104103
this.physicalAllMD = physicalAllMD;
104+
this.spl = new ThreadLoggerFactory(
105+
null,
106+
ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()
107+
).getLogger();
105108
}
106109

107110
/**
@@ -152,23 +155,6 @@ public String doInBackground() {
152155
String tmp;
153156
int counter = 0;
154157
try {
155-
int localLogLevel, localLogStep;
156-
if (ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag()) {
157-
localLogLevel = SEDALibProgressLogger.OBJECTS_WARNINGS;
158-
localLogStep = 1;
159-
} else {
160-
localLogLevel = SEDALibProgressLogger.OBJECTS_GROUP;
161-
localLogStep = 1000;
162-
}
163-
spl = new SEDALibProgressLogger(
164-
ResipLogger.getGlobalLogger().getLogger(),
165-
localLogLevel,
166-
null,
167-
localLogStep,
168-
2,
169-
SEDALibProgressLogger.OBJECTS_GROUP,
170-
1000
171-
);
172158
spl.setDebugFlag(ResipGraphicApp.getTheApp().interfaceParameters.isDebugFlag());
173159
dataObjectPackage = ResipGraphicApp.getTheApp().currentWork.getDataObjectPackage();
174160

0 commit comments

Comments
 (0)