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