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: import javax.portlet.PortletSession;
028:
029: import org.apache.geronimo.console.MultiPageModel;
030: import org.apache.geronimo.kernel.repository.Artifact;
031: import org.apache.geronimo.system.plugin.DownloadResults;
032: import org.apache.geronimo.system.plugin.PluginInstaller;
033: import org.apache.geronimo.system.plugin.ServerArchiver;
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: 627838 $ $Date: 2008-02-14 10:54:30 -0800 (Thu, 14 Feb 2008) $
042: */
043: public class AssemblyViewHandler extends BaseImportExportHandler {
044:
045: public AssemblyViewHandler() {
046: super (ASSEMBLY_VIEW_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[] pluginIds = request.getParameterValues("plugin");
054: String relativeServerPath = request
055: .getParameter("relativeServerPath");
056: String groupId = request.getParameter("groupId");
057: String artifactId = request.getParameter("artifactId");
058: String version = request.getParameter("version");
059: String format = request.getParameter("format");
060:
061: response.setRenderParameter("pluginIds", pluginIds);
062: response.setRenderParameter("relativeServerPath",
063: isEmpty(relativeServerPath) ? "var/temp/assembly"
064: : relativeServerPath);
065: if (!isEmpty(groupId))
066: response.setRenderParameter("groupId", groupId);
067: if (!isEmpty(artifactId))
068: response.setRenderParameter("artifactId", artifactId);
069: if (!isEmpty(version))
070: response.setRenderParameter("version", version);
071: if (!isEmpty(format))
072: response.setRenderParameter("format", format);
073:
074: return getMode();
075: }
076:
077: public void renderView(RenderRequest request,
078: RenderResponse response, MultiPageModel model)
079: throws PortletException, IOException {
080: PluginInstaller pluginInstaller = ManagementHelper
081: .getManagementHelper(request).getPluginInstaller();
082:
083: String[] configIds = request.getParameterValues("pluginIds");
084: String relativeServerPath = request
085: .getParameter("relativeServerPath");
086: String groupId = request.getParameter("groupId");
087: String artifactId = request.getParameter("artifactId");
088: String version = request.getParameter("version");
089: String format = request.getParameter("format");
090:
091: PluginListType list = getServerPluginList(request,
092: pluginInstaller);
093: PluginListType installList = getPluginsFromIds(configIds, list);
094: List<PluginInfoBean> plugins = new ArrayList<PluginInfoBean>();
095: for (PluginType pluginType : installList.getPlugin()) {
096: PluginInfoBean infoBean = new PluginInfoBean();
097: infoBean.setPlugin(pluginType);
098: infoBean.setPluginArtifact(pluginType.getPluginArtifact()
099: .get(0));
100: plugins.add(infoBean);
101: }
102:
103: request.setAttribute("plugins", plugins);
104: request.setAttribute("relativeServerPath", relativeServerPath);
105: request.setAttribute("groupId", groupId);
106: request.setAttribute("artifactId", artifactId);
107: request.setAttribute("version", version);
108: request.setAttribute("format", format);
109:
110: PortletSession assemblysession = request
111: .getPortletSession(true);
112: assemblysession.setAttribute("plugins", plugins);
113:
114: request.setAttribute("allInstallable", true);
115: request.setAttribute("mode", ASSEMBLY_VIEW_MODE + "-after");
116: }
117:
118: public String actionAfterView(ActionRequest request,
119: ActionResponse response, MultiPageModel model)
120: throws PortletException, IOException {
121: String relativeServerPath = request
122: .getParameter("relativeServerPath");
123: String groupId = request.getParameter("groupId");
124: String artifactId = request.getParameter("artifactId");
125: String version = request.getParameter("version");
126: String format = request.getParameter("format");
127:
128: response.setRenderParameter("relativeServerPath",
129: relativeServerPath);
130:
131: PluginInstaller pluginInstaller = ManagementHelper
132: .getManagementHelper(request).getPluginInstaller();
133: ServerArchiver archiver = ManagementHelper.getManagementHelper(
134: request).getArchiver();
135: String[] configIds = request.getParameterValues("configId");
136:
137: PluginListType list = getServerPluginList(request,
138: pluginInstaller);
139: PluginListType installList = getPluginsFromIds(configIds, list);
140:
141: try {
142: DownloadResults downloadResults = pluginInstaller
143: .installPluginList("repository",
144: relativeServerPath, installList);
145: archiver.archive(relativeServerPath, "var/temp",
146: new Artifact(groupId, artifactId, version, format));
147: } catch (Exception e) {
148: throw new PortletException("Could not assemble server", e);
149: }
150: return ASSEMBLY_CONFIRM_MODE + BEFORE_ACTION;
151: }
152:
153: }
|