Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java @ 1022:28a0628b11b0
Added license file and license header.
gnv/trunk@1258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 02 Nov 2010 17:15:08 +0000 |
parents | 1b42a86184f6 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.action; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import de.intevation.gnv.action.sessionmodel.SessionModel; import de.intevation.gnv.action.sessionmodel.SessionModelFactory; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseInputException; import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; import de.intevation.gnv.artifactdatabase.objects.InputParameter; /** * This controller feeds the artifact server with the current input data and * refreshes the gui with the current artifact description after the next state * is reached. * * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class NextArtifactStepAction extends DescribeUIAction { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger .getLogger(SelectArtifactFactoryAction.class); /** * Constructor */ public NextArtifactStepAction() { super(); } @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("NextArtifactStepAction.execute"); SessionModel sm = SessionModelFactory.getInstance() .getSessionModel(request); ArtifactDescription ad = sm.getArtifactDescription(); Locale tmp = sm.getCurrentLocale(); Locale locale = tmp != null ? tmp : request.getLocale(); if (ad != null){ Collection<String> inputParameter = ad.getInputParameter(); Collection<InputParameter> ips = null; if (inputParameter != null) { ips = new ArrayList<InputParameter>(inputParameter.size()); Iterator<String> it = inputParameter.iterator(); while (it.hasNext()) { String name = it.next(); String[] values = request.getParameterValues(name); InputParameter ip = new DefaultInputParameter(name, values); ips.add(ip); } } ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory .getInstance().getArtifactDatabaseClient(locale); Map outs = ad.getOutputModes(); if (outs == null || outs.isEmpty()) { // TODO: Woher kommt der zu erreichende Status; String target = null; if (ad.getReachableStates().size() > 1) { target = request.getParameter("product"); // TODO HACK for // Propducts every // other Step has // currently only // one reachable // state. } else { target = ad.getReachableStates().iterator().next(); } try { adc.doNextStep( sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), target, ips ); } catch (ArtifactDatabaseInputException e) { log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_INPUT_ID, e.getMessage()); } catch (Exception e) { log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e.getMessage()); } Map tmpOuts = ad.getOutputModes(); request.setAttribute( "furthertargets", tmpOuts == null || tmpOuts.isEmpty() ); } else { try{ adc.getCurrentStepDescription( sm.getSelectedArtifactFactory(), sm.getCurrentArtifact(), true ); request.setAttribute("diagramm", true); } catch (ArtifactDatabaseInputException e) { log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_INPUT_ID, e.getMessage()); } catch (Exception e) { log.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e.getMessage()); } request.setAttribute("furthertargets", false); } }else{ log.warn("SessionTimeout has occured"); return sessionExhaustedForward(mapping, form, request, response); } return super.execute(mapping, form, request, response); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :