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.ArrayList;
022 import java.util.List;
023
024
025
026 import javax.portlet.ActionRequest;
027 import javax.portlet.ActionResponse;
028 import javax.portlet.PortletException;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031
032
033 import org.apache.geronimo.console.car.ManagementHelper;
034 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
035 import org.apache.geronimo.console.MultiPageModel;
036 import org.apache.geronimo.kernel.repository.Artifact;
037 import org.apache.geronimo.system.plugin.DownloadResults;
038 import org.apache.geronimo.system.plugin.PluginInstaller;
039
040 /**
041 * Handler for the initial download screen.
042 *
043 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
044 */
045 public class DownloadStatusHandler extends BaseImportExportHandler {
046 public DownloadStatusHandler() {
047 super(DOWNLOAD_STATUS_MODE, "/WEB-INF/view/car/downloadStatus.jsp");
048 }
049
050 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
051 return getMode();
052
053 }
054
055 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
056 String[] configId = request.getParameterValues("configIds");
057 String repo = request.getParameter("repository");
058 String user = request.getParameter("repo-user");
059 String pass = request.getParameter("repo-pass");
060 String downloadKey = request.getParameter("downloadKey");
061
062 request.setAttribute("repository", repo);
063 request.setAttribute("repouser", user);
064 request.setAttribute("repopass", pass);
065 request.setAttribute("downloadKey", downloadKey);
066 request.setAttribute("configIds", configId);
067
068 }
069
070 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
071 PluginInstallerGBean pluginInstaller = (PluginInstallerGBean) ManagementHelper.getManagementHelper(request).getPluginInstaller();
072 String[] configId = request.getParameterValues("configId");
073 String repo = request.getParameter("repository");
074 String user = request.getParameter("repo-user");
075 String pass = request.getParameter("repo-pass");
076 int downloadKey = Integer.parseInt(request.getParameter("download-key"));
077 DownloadResults results = pluginInstaller.checkOnInstall(downloadKey, true);
078
079 List<InstallResults> dependencies = new ArrayList<InstallResults>();
080 if (results != null) {
081 if(results.isFailed()) {
082 //TODO is this an appropriate way to explain failure?
083 throw new PortletException("Unable to install configuration", results.getFailure());
084 }
085 for (Artifact uri: results.getDependenciesInstalled()) {
086 dependencies.add(new InstallResults(uri.toString(), "installed"));
087 }
088 for (Artifact uri: results.getDependenciesPresent()) {
089 dependencies.add(new InstallResults(uri.toString(), "already present"));
090 }
091 }
092 request.getPortletSession(true).setAttribute("car.install.results", dependencies);
093 response.setRenderParameter("configId", configId);
094 response.setRenderParameter("repository", repo);
095 if(!isEmpty(user)) response.setRenderParameter("repo-user", user);
096 if(!isEmpty(pass)) response.setRenderParameter("repo-pass", pass);
097 return RESULTS_MODE+BEFORE_ACTION;
098 }
099
100 public static class InstallResults implements Serializable {
101 private static final long serialVersionUID = -3745382506085182610L;
102 private String name;
103 private String action;
104
105 public InstallResults(String name, String action) {
106 this.name = name;
107 this.action = action;
108 }
109
110 public String getName() {
111 return name;
112 }
113
114 public String getAction() {
115 return action;
116 }
117 }
118 }