/**
 * Copyright (C) 2013
 * by 52 North Initiative for Geospatial Open Source Software GmbH
 *
 * Contact: Andreas Wytzisk
 * 52 North Initiative for Geospatial Open Source Software GmbH
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * This program is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed WITHOUT ANY WARRANTY; even without the implied
 * WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program (see gnu-gpl v2.txt). If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or
 * visit the Free Software Foundation web page, http://www.fsf.org.
 */
package org.n52.sos.binding.rest.resources.observations;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.opengis.sos.x20.InsertObservationResponseDocument;

import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.n52.sos.binding.rest.requests.RequestHandler;
import org.n52.sos.binding.rest.requests.RestRequest;
import org.n52.sos.binding.rest.requests.RestResponse;
import org.n52.sos.binding.rest.resources.features.FeatureByIdRequest;
import org.n52.sos.binding.rest.resources.features.FeatureByIdResponse;
import org.n52.sos.binding.rest.resources.features.FeaturesDecoder;
import org.n52.sos.binding.rest.resources.features.FeaturesRequestHandler;
import org.n52.sos.ogc.om.OmObservation;
import org.n52.sos.ogc.ows.OwsExceptionReport;
import org.n52.sos.request.GetFeatureOfInterestRequest;
import org.n52.sos.request.InsertObservationRequest;
import org.n52.sos.response.GetFeatureOfInterestResponse;

import com.google.gson.Gson;
import com.redch.AMQPService;
import com.redch.AMQPServiceImpl;
import com.redch.Sample;

/**
 * @author <a href="mailto:e.h.juerrens@52north.org">Eike Hinderk J&uuml;rrens</a>
 *
 */
public class ObservationsPostRequestHandler extends RequestHandler {
    
    @Override
    public RestResponse handleRequest(RestRequest req) throws OwsExceptionReport, XmlException
    {
        if (req != null && req instanceof ObservationsPostRequest) {
            InsertObservationRequest ioReq = ((ObservationsPostRequest) req).getInsertObservationRequest();
            
            // 2 handle core response
            XmlObject xb_InsertObservationResponse = executeSosRequest(ioReq);
            
            if (xb_InsertObservationResponse instanceof InsertObservationResponseDocument) {
                // 3 return response
                // no interesting content, just check the class to be sure that the insertion was successful
                // the restful response requires the link to the newly created observation
            	// FIXME we are always using only the first observation in the list without checking
                return new ObservationsPostResponse(
                        ioReq.getObservations().get(0).getIdentifier().getValue(),
                        ((ObservationsPostRequest) req).getXb_OMObservation());
            } 
        }
        throw logRequestTypeNotSupportedByThisHandlerAndCreateException(req,this.getClass().getName());
    }

}

@@ -1019,152 +1019,8 @@
 s;%0A%0A
-import java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 impo
@@ -1346,647 +1346,87 @@
 sos.
-binding.rest.resources.features.FeatureByIdRequest;%0Aimport org.n52.sos.binding.rest.resources.features.FeatureByIdResponse;%0Aimport org.n52.sos.binding.rest.resources.features.FeaturesDecoder;%0Aimport org.n52.sos.binding.rest.resources.features.FeaturesRequestHandler;%0Aimport org.n52.sos.ogc.om.OmObservation;%0Aimport org.n52.sos.ogc.ows.OwsExceptionReport;%0Aimport org.n52.sos.request.GetFeatureOfInterestRequest;%0Aimport org.n52.sos.request.InsertObservationRequest;%0Aimport org.n52.sos.response.GetFeatureOfInterestResponse;%0A%0Aimport com.google.gson.Gson;%0Aimport com.redch.AMQPService;%0Aimport com.redch.AMQPServiceImpl;%0Aimport com.redch.Sample
+ogc.ows.OwsExceptionReport;%0Aimport org.n52.sos.request.InsertObservationRequest
 ;%0A%0A/

Clean unused imports