1 package fr.ifremer.quadrige3.ui.swing.synchro.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import fr.ifremer.quadrige3.core.service.ClientServiceLocator;
28 import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIHandler;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.nuiton.i18n.I18n;
32
33 import java.io.File;
34
35 import static org.nuiton.i18n.I18n.t;
36
37
38
39
40
41
42 public abstract class AbstractUploadAction extends AbstractSynchroAction {
43
44 private static final Log log = LogFactory.getLog(AbstractUploadAction.class);
45
46 private File fileToUpload;
47
48
49
50
51
52
53 public abstract File getFileToUpload();
54
55
56
57
58
59
60 public AbstractUploadAction(SynchroUIHandler handler) {
61 super(handler);
62 }
63
64
65 @Override
66 public boolean initAction() {
67 super.initAction();
68
69 fileToUpload = getFileToUpload();
70
71 if (fileToUpload == null) {
72 log.error("no file to upload");
73 return false;
74 }
75
76 return true;
77 }
78
79
80 @Override
81 public void doAction() {
82
83 if (!fileToUpload.exists()) {
84 throw new SynchroException(I18n.t("quadrige3.error.file.not.exists", fileToUpload.getAbsolutePath()));
85 }
86
87 getModel().getProgressionModel().setMessage(t("quadrige3.synchro.progress.upload"));
88
89
90 ClientServiceLocator.instance().getSynchroRestClientService().uploadExportFile(
91 getContext().getAuthenticationInfo(),
92 fileToUpload,
93 getModel().getProgressionModel()
94 );
95 }
96
97
98 @Override
99 public void doneAction() {
100 }
101
102 }