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.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 import javax.portlet.PortletSession; 029 030 import org.apache.geronimo.console.MultiPageModel; 031 import org.apache.geronimo.kernel.repository.Artifact; 032 import org.apache.geronimo.system.plugin.DownloadResults; 033 import org.apache.geronimo.system.plugin.PluginInstaller; 034 import org.apache.geronimo.system.plugin.ServerArchiver; 035 import org.apache.geronimo.system.plugin.model.PluginListType; 036 import org.apache.geronimo.system.plugin.model.PluginType; 037 038 /** 039 * Handler for the screen that shows you plugin details before you go on and 040 * install it. 041 * 042 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $ 043 */ 044 public class AssemblyViewHandler extends BaseImportExportHandler { 045 046 public AssemblyViewHandler() { 047 super(ASSEMBLY_VIEW_MODE, "/WEB-INF/view/car/viewForDownload.jsp"); 048 } 049 050 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 051 String configId = request.getParameter("configId"); 052 String[] pluginIds = request.getParameterValues("plugin"); 053 if (configId != null) { 054 pluginIds = new String[]{configId}; 055 } 056 String relativeServerPath = request.getParameter("relativeServerPath"); 057 String groupId = request.getParameter("groupId"); 058 String artifactId = request.getParameter("artifactId"); 059 String version = request.getParameter("version"); 060 String format = request.getParameter("format"); 061 062 response.setRenderParameter("clickedConfigId", isEmpty(configId) ? "" : configId); 063 response.setRenderParameter("pluginIds", pluginIds); 064 response.setRenderParameter("relativeServerPath", isEmpty(relativeServerPath) ? "var/temp/assembly" : relativeServerPath); 065 if(!isEmpty(groupId)) response.setRenderParameter("groupId", groupId); 066 if(!isEmpty(artifactId)) response.setRenderParameter("artifactId", artifactId); 067 response.setRenderParameter("version", isEmpty(version) ? "1.0" : version); 068 if(!isEmpty(format)) response.setRenderParameter("format", format); 069 070 return getMode(); 071 } 072 073 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 074 PluginInstaller pluginInstaller = ManagementHelper.getManagementHelper(request).getPluginInstaller(); 075 076 String clickedConfigId = request.getParameter("clickedConfigId"); 077 String[] configIds = request.getParameterValues("pluginIds"); 078 String relativeServerPath = request.getParameter("relativeServerPath"); 079 String groupId = request.getParameter("groupId"); 080 String artifactId = request.getParameter("artifactId"); 081 String version = request.getParameter("version"); 082 String format = request.getParameter("format"); 083 084 PluginListType list = getServerPluginList(request, pluginInstaller); 085 PluginListType installList = getPluginsFromIds(configIds, list); 086 List<PluginInfoBean> plugins = new ArrayList<PluginInfoBean>(); 087 for (PluginType pluginType: installList.getPlugin()) { 088 PluginInfoBean infoBean = new PluginInfoBean(); 089 infoBean.setPlugin(pluginType); 090 infoBean.setPluginArtifact(pluginType.getPluginArtifact().get(0)); 091 plugins.add(infoBean); 092 } 093 094 request.setAttribute("clickedConfigId", clickedConfigId); 095 request.setAttribute("plugins", plugins); 096 request.setAttribute("relativeServerPath", relativeServerPath); 097 request.setAttribute("groupId", groupId); 098 request.setAttribute("artifactId", artifactId); 099 request.setAttribute("version", version); 100 request.setAttribute("format", format); 101 102 PortletSession assemblysession = request.getPortletSession(true); 103 assemblysession.setAttribute("plugins", plugins); 104 105 request.setAttribute("allInstallable", true); 106 request.setAttribute("mode", ASSEMBLY_VIEW_MODE + "-after"); 107 } 108 109 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 110 String relativeServerPath = request.getParameter("relativeServerPath"); 111 String groupId = request.getParameter("groupId"); 112 String artifactId = request.getParameter("artifactId"); 113 String version = request.getParameter("version"); 114 String format = request.getParameter("format"); 115 116 response.setRenderParameter("relativeServerPath",relativeServerPath); 117 118 PluginInstaller pluginInstaller = ManagementHelper.getManagementHelper(request).getPluginInstaller(); 119 ServerArchiver archiver = ManagementHelper.getManagementHelper(request).getArchiver(); 120 String[] configIds = request.getParameterValues("configId"); 121 122 PluginListType list = getServerPluginList(request, pluginInstaller); 123 PluginListType installList = getPluginsFromIds(configIds, list); 124 125 126 try { 127 DownloadResults downloadResults = pluginInstaller.installPluginList("repository", relativeServerPath, installList); 128 archiver.archive(relativeServerPath, "var/temp", new Artifact(groupId, artifactId, version, format)); 129 } catch (Exception e) { 130 throw new PortletException("Could not assemble server", e); 131 } 132 return ASSEMBLY_CONFIRM_MODE+BEFORE_ACTION; 133 } 134 135 }