001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.console.car;
018    
019    import java.io.IOException;
020    import java.io.Serializable;
021    import java.util.List;
022    import java.util.ArrayList;
023    import javax.portlet.ActionRequest;
024    import javax.portlet.ActionResponse;
025    import javax.portlet.PortletException;
026    import javax.portlet.RenderRequest;
027    import javax.portlet.RenderResponse;
028    import org.apache.commons.logging.Log;
029    import org.apache.commons.logging.LogFactory;
030    import org.apache.geronimo.console.MultiPageModel;
031    import org.apache.geronimo.kernel.repository.Artifact;
032    import org.apache.geronimo.system.plugin.DownloadResults;
033    
034    /**
035     * Handler for the initial download screen.
036     *
037     * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
038     */
039    public class DownloadStatusHandler extends BaseImportExportHandler {
040        private final static Log log = LogFactory.getLog(DownloadStatusHandler.class);
041    
042        public DownloadStatusHandler() {
043            super(DOWNLOAD_STATUS_MODE, "/WEB-INF/view/car/downloadStatus.jsp");
044        }
045    
046        public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
047            return getMode();
048        }
049    
050        public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
051            String configId = request.getParameter("configId");
052            String repo = request.getParameter("repository");
053            String user = request.getParameter("repo-user");
054            String pass = request.getParameter("repo-pass");
055            request.setAttribute("configId", configId);
056            request.setAttribute("repository", repo);
057            request.setAttribute("repouser", user);
058            request.setAttribute("repopass", pass);
059        }
060    
061        public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
062            String repo = request.getParameter("repository");
063            String user = request.getParameter("repo-user");
064            String pass = request.getParameter("repo-pass");
065            String configId = request.getParameter("configId");
066    
067            DownloadResults results = (DownloadResults) request.getPortletSession(true).getAttribute(DOWNLOAD_RESULTS_SESSION_KEY);
068            if(results.isFailed()) {
069                throw new PortletException("Unable to install configuration", results.getFailure());
070            }
071            List dependencies = new ArrayList();
072            for (int i = 0; i < results.getDependenciesInstalled().length; i++) {
073                Artifact uri = results.getDependenciesInstalled()[i];
074                dependencies.add(new InstallResults(uri.toString(), "installed"));
075            }
076            for (int i = 0; i < results.getDependenciesPresent().length; i++) {
077                Artifact uri = results.getDependenciesPresent()[i];
078                dependencies.add(new InstallResults(uri.toString(), "already present"));
079            }
080            request.getPortletSession(true).setAttribute("car.install.results", dependencies);
081    
082            response.setRenderParameter("configId", configId);
083            response.setRenderParameter("repository", repo);
084            if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
085            if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
086            return RESULTS_MODE+BEFORE_ACTION;
087        }
088    
089        public static class InstallResults implements Serializable {
090            private String name;
091            private String action;
092    
093            public InstallResults(String name, String action) {
094                this.name = name;
095                this.action = action;
096            }
097    
098            public String getName() {
099                return name;
100            }
101    
102            public String getAction() {
103                return action;
104            }
105        }
106    }