001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/csw/discovery/GetRecordById.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2006 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/deegree/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     This library is free software; you can redistribute it and/or
012     modify it under the terms of the GNU Lesser General Public
013     License as published by the Free Software Foundation; either
014     version 2.1 of the License, or (at your option) any later version.
015    
016     This library is distributed in the hope that it will be useful,
017     but WITHOUT ANY WARRANTY; without even the implied warranty of
018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019     Lesser General Public License for more details.
020    
021     You should have received a copy of the GNU Lesser General Public
022     License along with this library; if not, write to the Free Software
023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024    
025     Contact:
026    
027     Andreas Poth
028     lat/lon GmbH
029     Aennchenstr. 19
030     53115 Bonn
031     Germany
032     E-Mail: poth@lat-lon.de
033    
034     Prof. Dr. Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: greve@giub.uni-bonn.de
041    
042     ---------------------------------------------------------------------------*/
043    package org.deegree.ogcwebservices.csw.discovery;
044    
045    import java.util.Map;
046    
047    import org.deegree.framework.util.IDGenerator;
048    import org.deegree.framework.util.StringTools;
049    import org.deegree.ogcwebservices.InvalidParameterValueException;
050    import org.deegree.ogcwebservices.MissingParameterValueException;
051    import org.deegree.ogcwebservices.OGCWebServiceException;
052    import org.deegree.ogcwebservices.csw.AbstractCSWRequest;
053    import org.deegree.ogcwebservices.csw.NonexistentCollectionException;
054    import org.deegree.ogcwebservices.csw.NonexistentTypeException;
055    import org.w3c.dom.Element;
056    
057    /**
058     * The mandatory GetRecordById request retrieves the default representation of catalogue records
059     * using their identifier. The GetRecordById operation is an implementation of the Present operation
060     * from the general model. This operation presumes that a previous query has been performed in order
061     * to obtain the identifiers that may be used with this operation. For example, records returned by
062     * a GetRecords operation may contain references to other records in the catalogue that may be
063     * retrieved using the GetRecordById operation. This operation is also a subset of the GetRecords
064     * operation, and is included as a convenient short form for retrieving and linking to records in a
065     * catalogue.
066     * 
067     * @version $Revision: 6820 $
068     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
069     * @author last edited by: $Author: apoth $
070     * 
071     * @version 1.0. $Revision: 6820 $, $Date: 2007-05-04 16:19:40 +0200 (Fr, 04 Mai 2007) $
072     * 
073     * @since 2.0
074     */
075    public class GetRecordById extends AbstractCSWRequest {
076    
077        private static final long serialVersionUID = -3602776884510160189L;
078    
079        private String[] ids = null;
080    
081        private String elementSetName = null;
082    
083        /**
084         * creates a <code>GetRecordById</code> request from the XML fragment passed. The passed
085         * element must be valid against the OGC CSW 2.0 GetRecordById schema.
086         * 
087         * @param id
088         *            unique ID of the request
089         * @param root
090         *            root element of the GetRecors request
091         * @return a GetRecordById bean representation created from the xml fragment.
092         * @throws MissingParameterValueException
093         * @throws InvalidParameterValueException
094         * @throws OGCWebServiceException
095         */
096        public static GetRecordById create( String id, Element root )
097                                throws MissingParameterValueException, InvalidParameterValueException,
098                                OGCWebServiceException {
099    
100            GetRecordByIdDocument document = new GetRecordByIdDocument();
101            document.setRootElement( root );
102            GetRecordById ogcRequest = document.parseGetRecordById( id );
103    
104            return ogcRequest;
105        }
106    
107        /**
108         * Creates a new <code>GetRecordById</code> instance from the values stored in the submitted
109         * Map. Keys (parameter names) in the Map must be uppercase.
110         * 
111         * @TODO evaluate vendorSpecificParameter
112         * 
113         * @param kvp
114         *            Map containing the parameters
115         * @return a GetRecordById bean representation, the internal request id will be set to
116         *         Long.toString( IDGenerator.getInstance().generateUniqueID() ).
117         * @exception InvalidParameterValueException
118         * @exception MissingParameterValueException
119         * @exception NonexistentCollectionException
120         * @exception NonexistentTypeException
121         */
122        public static GetRecordById create( Map<String, String> kvp ) {
123    
124            String version = kvp.remove( "VERSION" );
125            String elementSetName = kvp.remove( "ELEMENTSETNAME" );
126            String tmp = kvp.remove( "ID" );
127            String[] ids = StringTools.toArray( tmp, ",", true );
128    
129            return new GetRecordById( Long.toString( IDGenerator.getInstance().generateUniqueID() ), 
130                                      version, kvp, ids,
131                                      elementSetName );
132        }
133    
134        /**
135         * Creates a new <code>GetRecordById</code> instance from the values stored in the submitted
136         * Map. Keys (parameter names) in the Map must be uppercase.
137         * 
138         * @param id
139         *            of the request, and not the requested ids.
140         * 
141         * @TODO evaluate vendorSpecificParameter
142         * 
143         * @param kvp
144         *            Map containing the parameters
145         * @return a GetRecordById bean representation.
146         * @exception InvalidParameterValueException
147         * @exception MissingParameterValueException
148         * @exception NonexistentCollectionException
149         * @exception NonexistentTypeException
150         */
151        public static GetRecordById create( String id, Map<String, String> kvp ) {
152    
153            String version = kvp.remove( "VERSION" );
154            String elementSetName = kvp.remove( "ELEMENTSETNAME" );
155            String tmp = kvp.remove( "ID" );
156            String[] ids = StringTools.toArray( tmp, ",", true );
157    
158            return new GetRecordById( id, version, kvp, ids, elementSetName );
159        }
160    
161        /**
162         * 
163         * @param ids
164         *            identifiers of the requested catalogue entries
165         * @param elementSetName
166         *            requested element set (brief|summary|full). Can be <code>null</code>; will be
167         *            treaded as full.
168         */
169        GetRecordById( String id, String version, Map<String, String> vendorSpecificParameters, String[] ids,
170                       String elementSetName ) {
171            super( version, id, vendorSpecificParameters );
172            this.ids = ids;
173            this.elementSetName = elementSetName;
174        }
175    
176        /**
177         * @return the requested element set name. If the returned value equals <code>null</code> a
178         *         'summary' request shall be performed. possible values are:
179         *         <ul>
180         *         <li>brief</li>
181         *         <li>summary</li>
182         *         <li>full</li>
183         *         </ul>
184         * 
185         */
186        public String getElementSetName() {
187            return elementSetName;
188        }
189    
190        /**
191         * @return the requested ids as an array of strings
192         */
193        public String[] getIds() {
194            return ids;
195        }
196    }