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.util.List;
021    import javax.portlet.ActionRequest;
022    import javax.portlet.ActionResponse;
023    import javax.portlet.PortletException;
024    import javax.portlet.RenderRequest;
025    import javax.portlet.RenderResponse;
026    import org.apache.commons.logging.Log;
027    import org.apache.commons.logging.LogFactory;
028    import org.apache.geronimo.console.MultiPageModel;
029    import org.apache.geronimo.kernel.KernelRegistry;
030    import org.apache.geronimo.kernel.config.ConfigurationManager;
031    import org.apache.geronimo.kernel.config.ConfigurationUtil;
032    import org.apache.geronimo.kernel.repository.Artifact;
033    
034    /**
035     * Handler for the import results screen.
036     *
037     * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
038     */
039    public class ResultsHandler extends BaseImportExportHandler {
040        private final static Log log = LogFactory.getLog(ResultsHandler.class);
041    
042        public ResultsHandler() {
043            super(RESULTS_MODE, "/WEB-INF/view/car/results.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 repo = request.getParameter("repository");
052            String user = request.getParameter("repo-user");
053            String pass = request.getParameter("repo-pass");
054            String configId = request.getParameter("configId");
055            request.setAttribute("configId", configId);
056            List deps = (List) request.getPortletSession(true).getAttribute("car.install.results");
057            request.setAttribute("dependencies", deps);
058            request.setAttribute("repository", repo);
059            request.setAttribute("repouser", user);
060            request.setAttribute("repopass", pass);
061        }
062    
063        public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
064            String configId = request.getParameter("configId");
065            String repo = request.getParameter("repository");
066            String user = request.getParameter("repo-user");
067            String pass = request.getParameter("repo-pass");
068            response.setRenderParameter("repository", repo);
069            if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
070            if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
071            try {
072                //todo: hide this in PortletManager/ManagementHelper
073                ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(KernelRegistry.getSingleKernel());
074                Artifact artifact = Artifact.create(configId);
075                mgr.loadConfiguration(artifact);
076                mgr.startConfiguration(artifact);
077                return LIST_MODE;
078            } catch (Exception e) {
079                log.error("Unable to start configuration "+configId, e);
080                response.setRenderParameter("configId", configId);
081                return getMode()+BEFORE_ACTION;
082            }
083        }
084    }