    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/standard/security/control/UpdateObjectsListener.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.portal.standard.security.control;
    037
    038    import static org.deegree.framework.log.LoggerFactory.getLogger;
    039    import static org.deegree.framework.util.StringTools.stackTraceToString;
    040    import static org.deegree.i18n.Messages.get;
    041    import static org.deegree.portal.standard.security.control.SecurityHelper.acquireTransaction;
    042    import static org.deegree.portal.standard.security.control.SecurityHelper.checkForAdminRole;
    043    import static org.deegree.security.drm.SecurityAccessManager.getInstance;
    044
    045    import javax.servlet.ServletRequest;
    046
    047    import org.deegree.enterprise.control.AbstractListener;
    048    import org.deegree.enterprise.control.FormEvent;
    049    import org.deegree.enterprise.control.RPCMember;
    050    import org.deegree.enterprise.control.RPCParameter;
    051    import org.deegree.enterprise.control.RPCStruct;
    052    import org.deegree.enterprise.control.RPCWebEvent;
    053    import org.deegree.framework.log.ILogger;
    054    import org.deegree.i18n.Messages;
    055    import org.deegree.security.GeneralSecurityException;
    056    import org.deegree.security.drm.SecurityAccessManager;
    057    import org.deegree.security.drm.SecurityTransaction;
    058    import org.deegree.security.drm.model.Service;
    059
    060    /**
    061     * <code>ReallyUpdateServiceListener</code>
    062     *
    063     * @author <a href="mailto:schmitz@lat-lon.de">Andreas Schmitz</a>
    064     * @author last edited by: $Author: mschneider $
    065     *
    066     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    067     */
    068    public class UpdateObjectsListener extends AbstractListener {
    069
    070        private static final ILogger LOG = getLogger( UpdateObjectsListener.class );
    071
    072        @Override
    073        public void actionPerformed( FormEvent event ) {
    074            RPCParameter[] params = ( (RPCWebEvent) event ).getRPCMethodCall().getParameters();
    075
    076            ServletRequest request = getRequest();
    077
    078            SecurityTransaction transaction = null;
    079            SecurityAccessManager manager = null;
    080
    081            try {
    082                // perform access check
    083                manager = getInstance();
    084                transaction = acquireTransaction( this );
    085                checkForAdminRole( transaction );
    086
    087                String address = (String) params[0].getValue();
    088                Service service = transaction.getServiceByAddress( address );
    089                RPCParameter[] objs = (RPCParameter[]) params[1].getValue();
    090
    091                String newTitle = null, newAddress = null;
    092
    093                if ( params.length > 2 ) {
    094                    RPCMember title = ( (RPCStruct) params[2].getValue() ).getMember( "title" );
    095                    if ( title != null ) {
    096                        newTitle = (String) title.getValue();
    097                    }
    098                    RPCMember rpcaddress = ( (RPCStruct) params[2].getValue() ).getMember( "address" );
    099                    if ( rpcaddress != null ) {
    100                        newAddress = (String) rpcaddress.getValue();
    101                    }
    102                }
    103
    104                for ( int i = 0; i < objs.length; i += 2 ) {
    105                    transaction.renameObject( service, (String) objs[i].getValue(), (String) objs[i + 1].getValue() );
    106                }
    107
    108                Service newService = transaction.getServiceByAddress( service.getAddress() );
    109
    110                if ( newTitle != null || newAddress != null ) {
    111                    transaction.editService( newService, newTitle, newAddress );
    112                }
    113                manager.commitTransaction( transaction );
    114
    115                request.setAttribute( "MESSAGE", Messages.getMessage( "IGEO_STD_SEC_SUCCESS_INITSERVICESEDITOR" ) );
    116            } catch ( GeneralSecurityException e ) {
    117                getRequest().setAttribute( "SOURCE", this.getClass().getName() );
    118                getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_FAIL_INIT_SERVICES_EDITOR", e.getMessage() ) );
    119                setNextPage( "error.jsp" );
    120                LOG.logError( e.getMessage(), e );
    121                try {
    122                    if ( manager != null ) {
    123                        manager.abortTransaction( transaction );
    124                    }
    125                } catch ( GeneralSecurityException e1 ) {
    126                    LOG.logError( "Unknown error", e1 );
    127                }
    128            } catch ( Exception e ) {
    129                LOG.logError( get( "IGEO_STD_SEC_ERROR_UNKNOWN", stackTraceToString( e ) ) );
    130                try {
    131                    if ( manager != null ) {
    132                        manager.abortTransaction( transaction );
    133                    }
    134                } catch ( GeneralSecurityException e1 ) {
    135                    LOG.logError( "Unknown error", e1 );
    136                    getRequest().setAttribute( "SOURCE", this.getClass().getName() );
    137                    getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_EDIT_SERVICE", e1.getMessage() ) );
    138                    setNextPage( "error.jsp" );
    139                    return;
    140
    141                }
    142                getRequest().setAttribute( "SOURCE", this.getClass().getName() );
    143                getRequest().setAttribute( "MESSAGE", get( "IGEO_STD_SEC_ERROR_EDIT_SERVICE", e.getMessage() ) );
    144                setNextPage( "error.jsp" );
    145            }
    146        }
    147
    148    }