View Javadoc
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.core.exception.QuadrigeTechnicalException;
28  import fr.ifremer.quadrige3.core.security.AuthenticationInfo;
29  import fr.ifremer.quadrige3.core.service.ClientServiceLocator;
30  import fr.ifremer.quadrige3.synchro.service.client.SynchroRestClientService;
31  import fr.ifremer.quadrige3.synchro.vo.SynchroImportContextVO;
32  import fr.ifremer.quadrige3.ui.swing.synchro.SynchroUIHandler;
33  import org.nuiton.i18n.I18n;
34  
35  /**
36   * <p>ImportSynchroAckAction class.</p>
37   *
38   * @author Ludovic Pecquot <ludovic.pecquot@e-is.pro>
39   */
40  public class ImportSynchroAckAction extends AbstractSynchroAction {
41  
42      /**
43       * <p>Constructor for ImportSynchroAckAction.</p>
44       *
45       * @param handler a {@link SynchroUIHandler} object.
46       */
47      public ImportSynchroAckAction(SynchroUIHandler handler) {
48          super(handler);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public void doAction() {
54  
55          SynchroRestClientService service = ClientServiceLocator.instance().getSynchroRestClientService();
56  
57          try {
58              // Check compatibility with server
59              service.checkVersion(getContext().getAuthenticationInfo());
60  
61              // No authentication (=Anonymous) if user is not authenticate or as local user (mantis #26658)
62              AuthenticationInfo authenticationInfo = !getContext().isAuthenticated() || getContext().isAuthenticatedAsLocalUser()
63                      ? null
64                      : getContext().getAuthenticationInfo();
65  
66              // Send the acknowledge
67              SynchroImportContextVO context = getModel().getSynchroImportContext();
68              service.acknowledgeImport(
69                      authenticationInfo,
70                      context);
71  
72          } catch (QuadrigeTechnicalException e) {
73              throw new SynchroException(I18n.t("quadrige3.error.synchro.connect", e.getMessage()), e);
74          }
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public void doneAction() {
80      }
81  
82  }