view gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java @ 683:d49e8695786c

Ordered imports. Removed needless imports. Removed empty headers. gnv/trunk@855 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 09:10:25 +0000
parents d3062dc8626a
children 57fa8019fbdc
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.ArtifactObject;

import java.util.Collection;

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>
 *
 */
public class SelectArtifactFactoryAction extends DescribeUIAction {
    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger
            .getLogger(SelectArtifactFactoryAction.class);

    /**
     * @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("SelectArtifactFactoryAction.execute");
        String selectedArtifactFactoryID = request
                .getParameter("artifactFactory");
        log.debug("Selected ArtifactFactory ==> " + selectedArtifactFactoryID);

        try {
            SessionModel sm = SessionModelFactory.getInstance()
                    .getSessionModel(request);
            Collection<ArtifactObject> artifactFactories = sm
                    .getArtifactFactories();
            // Removes the Artifactspecific Attributes from the SessionModel-
            sm.resetModel();
            if (artifactFactories == null || artifactFactories.isEmpty()) {
                new FetchArtifactFactoriesAction().execute(mapping, form,
                        request, response);

            }

            sm.selectArtifactFactory(selectedArtifactFactoryID);
            ArtifactObject af = sm.getSelectedArtifactFactory();
            ;
            ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory
                                                .getInstance()
                                                .getArtifactDatabaseClient(getLocale(request));
            ArtifactObject artifact = adc.createNewArtifact(af);
            sm.setCurrentArtifact(artifact);

            return super.execute(mapping, form, request, response);
        } catch (Exception e) {
            log.error(e, e);
            request.setAttribute(
                    CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
                            .getMessage());
            return super.getExceptionForward(mapping);
        }
    }

    /**
     * Constructor
     */
    public SelectArtifactFactoryAction() {
    }

}

http://dive4elements.wald.intevation.org