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.util.ArrayList;
020: import java.util.List;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletException;
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027:
028: import org.apache.geronimo.console.MultiPageModel;
029: import org.apache.geronimo.kernel.repository.Dependency;
030: import org.apache.geronimo.system.plugin.DownloadResults;
031: import org.apache.geronimo.system.plugin.PluginInstaller;
032: import org.apache.geronimo.system.plugin.PluginInstallerGBean;
033: import org.apache.geronimo.system.plugin.model.PluginArtifactType;
034: import org.apache.geronimo.system.plugin.model.PluginListType;
035: import org.apache.geronimo.system.plugin.model.PluginType;
036:
037: /**
038: * Handler for the screen that shows you plugin details before you go on and
039: * install it.
040: *
041: * @version $Rev: 617243 $ $Date: 2008-01-31 13:16:05 -0800 (Thu, 31 Jan 2008) $
042: */
043: public class ViewPluginDownloadHandler extends BaseImportExportHandler {
044:
045: public ViewPluginDownloadHandler() {
046: super (VIEW_FOR_DOWNLOAD_MODE,
047: "/WEB-INF/view/car/viewForDownload.jsp");
048: }
049:
050: public String actionBeforeView(ActionRequest request,
051: ActionResponse response, MultiPageModel model)
052: throws PortletException, IOException {
053: String configId = request.getParameter("configId");
054: String[] pluginIds = request.getParameterValues("plugin");
055: if (configId != null) {
056: pluginIds = new String[] { configId };
057: }
058: String repo = request.getParameter("repository");
059: String user = request.getParameter("repo-user");
060: String pass = request.getParameter("repo-pass");
061: response.setRenderParameter("pluginIds", pluginIds);
062: response.setRenderParameter("repository", repo);
063: if (!isEmpty(user))
064: response.setRenderParameter("repo-user", user);
065: if (!isEmpty(pass))
066: response.setRenderParameter("repo-pass", pass);
067:
068: return getMode();
069: }
070:
071: public void renderView(RenderRequest request,
072: RenderResponse response, MultiPageModel model)
073: throws PortletException, IOException {
074: PluginInstaller pluginInstaller = ManagementHelper
075: .getManagementHelper(request).getPluginInstaller();
076:
077: String[] configIds = request.getParameterValues("pluginIds");
078: String repo = request.getParameter("repository");
079: String user = request.getParameter("repo-user");
080: String pass = request.getParameter("repo-pass");
081:
082: PluginListType list = getRepoPluginList(request,
083: pluginInstaller, repo, user, pass);
084: PluginListType installList = getPluginsFromIds(configIds, list);
085: List<PluginInfoBean> plugins = new ArrayList<PluginInfoBean>();
086: for (PluginType pluginType : installList.getPlugin()) {
087: PluginInfoBean infoBean = new PluginInfoBean();
088: infoBean.setPlugin(pluginType);
089: infoBean.setPluginArtifact(pluginType.getPluginArtifact()
090: .get(0));
091: plugins.add(infoBean);
092: }
093:
094: boolean allInstallable = true;
095: // see if the plugin is installable. if not then provide the details
096: String validationOk = "All requirements for this plugin have been met.";
097: for (PluginInfoBean plugin : plugins) {
098: StringBuffer validationNotOk = new StringBuffer();
099: PluginType holder = PluginInstallerGBean.copy(plugin
100: .getPlugin(), plugin.getPluginArtifact());
101: try {
102: pluginInstaller.validatePlugin(holder);
103: } catch (Exception e) {
104: plugin.setInstallable(false);
105: validationNotOk.append(e.getMessage());
106: validationNotOk.append("<BR>\n");
107: }
108: Dependency[] missingPrereqs = pluginInstaller
109: .checkPrerequisites(holder);
110: if (missingPrereqs.length > 0) {
111: plugin.setInstallable(false);
112: for (Dependency dep : missingPrereqs) {
113: validationNotOk.append(" Missing prerequisite ");
114: validationNotOk
115: .append(dep.getArtifact().toString());
116: validationNotOk.append("<BR>\n");
117: }
118: }
119: if (plugin.isInstallable()) {
120: plugin.setValidationMessage(validationOk);
121: } else {
122: plugin.setValidationMessage(validationNotOk.toString());
123: allInstallable = false;
124: }
125: }
126: request.setAttribute("plugins", plugins);
127: request.setAttribute("repository", repo);
128: request.setAttribute("repouser", user);
129: request.setAttribute("repopass", pass);
130: request.setAttribute("allInstallable", allInstallable);
131: request.setAttribute("mode", "viewForDownload-after");
132: }
133:
134: public String actionAfterView(ActionRequest request,
135: ActionResponse response, MultiPageModel model)
136: throws PortletException, IOException {
137: PluginInstaller pluginInstaller = ManagementHelper
138: .getManagementHelper(request).getPluginInstaller();
139: String repo = request.getParameter("repository");
140: String user = request.getParameter("repo-user");
141: String pass = request.getParameter("repo-pass");
142: String[] configIds = request.getParameterValues("configId");
143:
144: PluginListType list = getRepoPluginList(request,
145: pluginInstaller, repo, user, pass);
146: PluginListType installList = getPluginsFromIds(configIds, list);
147:
148: Object downloadKey = pluginInstaller.startInstall(installList,
149: repo, false, user, pass);
150: DownloadResults results = pluginInstaller
151: .checkOnInstall(downloadKey);
152: request.getPortletSession(true).setAttribute(
153: DOWNLOAD_RESULTS_SESSION_KEY, results);
154:
155: response.setRenderParameter("configIds", configIds);
156: response.setRenderParameter("repository", repo);
157: response.setRenderParameter("downloadKey", downloadKey
158: .toString());
159:
160: if (!isEmpty(user))
161: response.setRenderParameter("repo-user", user);
162: if (!isEmpty(pass))
163: response.setRenderParameter("repo-pass", pass);
164: return DOWNLOAD_STATUS_MODE + BEFORE_ACTION;
165: }
166:
167: }
|