1 package fr.ifremer.quadrige3.ui.swing.synchro.action;
2
3 /*-
4 * #%L
5 * Quadrige3 Core :: Quadrige3 UI Common
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * #L%
24 */
25
26
27 import fr.ifremer.quadrige3.synchro.vo.SynchroProgressionStatus;
28 import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIHandler;
29
30 import java.io.File;
31
32 /**
33 * <p>ImportSynchroDownloadAction class.</p>
34 *
35 * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
36 */
37 public class ImportSynchroDownloadAction extends AbstractDownloadAction {
38
39 /**
40 * <p>Constructor for ImportSynchroDownloadAction.</p>
41 *
42 * @param handler a {@link SynchroUIHandler} object.
43 */
44 public ImportSynchroDownloadAction(SynchroUIHandler handler) {
45 super(handler);
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public boolean initAction() {
51 super.initAction();
52
53 getModel().setStatus(SynchroProgressionStatus.RUNNING);
54 getModel().saveImportContext();
55
56 return true;
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public File getTargetDirectory() {
62 return getModel().getImportDirectory();
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 public String getUrlPath() {
68 boolean isAnonymous = getContext().isAuthenticatedAsLocalUser();
69 return isAnonymous ? "/service/import/files/anonymous" : "/service/import/files";
70 }
71
72 /** {@inheritDoc} */
73 @Override
74 public void doneAction() {
75 super.doneAction();
76
77 getModel().setStatus(SynchroProgressionStatus.SUCCESS);
78
79 getModel().saveImportContext();
80
81 // if action launched with lock, don't chain action
82 if (isWait()) {
83 return;
84 }
85
86 getHandler().showValidApplyPopup();
87
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 public void failedAction(Throwable ex) {
93 super.failedAction(ex);
94
95 getModel().saveImportContext();
96
97 }
98
99 }