View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19  package nl.toolforge.karma.core.cmd.impl;
20  
21  import nl.toolforge.karma.core.boot.ManifestStore;
22  import nl.toolforge.karma.core.cmd.CommandDescriptor;
23  import nl.toolforge.karma.core.cmd.CommandException;
24  import nl.toolforge.karma.core.cmd.CommandResponse;
25  import nl.toolforge.karma.core.cmd.DefaultCommand;
26  import nl.toolforge.karma.core.cmd.event.ErrorEvent;
27  import nl.toolforge.karma.core.cmd.event.MessageEvent;
28  import nl.toolforge.karma.core.cmd.event.SimpleMessage;
29  import nl.toolforge.karma.core.vc.AuthenticationException;
30  import nl.toolforge.karma.core.vc.VersionControlException;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  /***
35   * Updates administrative data for a working context. The manifest-store and the location-store are updated.
36   *
37   * @author W.H. Schraal
38   * @author D.A. Smedes
39   *
40   * @version $Id: UpdateAdmin.java,v 1.1 2004/11/10 23:50:04 asmedes Exp $
41   */
42  public class UpdateAdmin extends DefaultCommand {
43  
44    private static final Log logger = LogFactory.getLog(UpdateAdmin.class);
45  
46    private CommandResponse commandResponse = new CommandResponse();
47  
48    public UpdateAdmin(CommandDescriptor descriptor) {
49      super(descriptor);
50    }
51  
52    public void execute() throws CommandException {
53  
54      try {
55        ManifestStore mStore = getContext().getWorkingContext().getConfiguration().getManifestStore();
56  
57        if (!mStore.getLocation().isAvailable()) {
58          commandResponse.addEvent(new MessageEvent(this, new SimpleMessage("Manifest store location unreachable!")));
59        } else {
60          commandResponse.addEvent(new MessageEvent(this, new SimpleMessage(("Updating manifests ..."))));
61          mStore.update();
62        }
63  
64        // todo locations are not yet reloaded automatically.
65  
66  //      LocationStore lStore = getContext().getWorkingContext().getConfiguration().getLocationStore();
67  //
68  //      if (!lStore.getLocation().isAvailable()) {
69  //        commandResponse.addEvent(new MessageEvent(this, new SimpleMessage("Location store location unreachable!")));
70  //      } else {
71  //        commandResponse.addEvent(new MessageEvent(this, new SimpleMessage(("Updating locations ..."))));
72  //        lStore.update();
73  //      }
74  
75      } catch (VersionControlException e) {
76        logger.warn(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments()));
77        commandResponse.addEvent(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments()));
78      } catch (AuthenticationException e) {
79        logger.warn(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments()));
80        commandResponse.addEvent(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments()));
81      }
82    }
83  
84    public CommandResponse getCommandResponse() {
85      return this.commandResponse;
86    }
87  }