view gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java @ 409:df78178e1180

Moved user interface creation to an own action. This makes avoids code duplication and makes it easier to write new action to handle special interactions, because there is no need for parsing the describe document and creating the user interface after this. gnv/trunk@599 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 22 Jan 2010 11:28:25 +0000
parents b5733f9f386b
children 27f25b9ae9af
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.action;
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.objects.ArtifactDescription;
import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter;
import de.intevation.gnv.artifactdatabase.objects.InputParameter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
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;


/**
 * @author Tim Englich <tim.englich@intevation.de>
 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
 * 
 */
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();
    }

    /**
     * @see de.intevation.gnv.action.ArtifactDatabaseActionBase#execute(org.apache.struts.action.ActionMapping,
     *      org.apache.struts.action.ActionForm,
     *      javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    @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();
            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(getLocale(request));
                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 (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 (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");
                request.setAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, 
                                     "SessionTimeout has occured");
                new FetchArtifactFactoriesAction().execute(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 :

http://dive4elements.wald.intevation.org