<commit_before>package com.axiomalaska.sos.xmlbuilder;

import java.util.Calendar;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.axiomalaska.phenomena.Phenomenon;
import com.axiomalaska.sos.data.SosSensor;
import com.axiomalaska.sos.data.SosStation;
import com.axiomalaska.sos.data.ObservationCollection;
import com.axiomalaska.sos.tools.IdCreator;

/**
 * Builds a SOS InsertObservation XML String with the ObservationCollection and station
 * 
 * @author <NAME>
 */
public class InsertObservationBuilder extends SosXmlBuilder {

	// -------------------------------------------------------------------------
	// Private Data
	// -------------------------------------------------------------------------
	
	private SosStation station;
	private SosSensor sensor;
	private ObservationCollection observationCollection;
	private IdCreator idCreator;
	private Phenomenon phenomenon;
	private Double depth;
	
	// -------------------------------------------------------------------------
	// Constructor
	// -------------------------------------------------------------------------
	
	public InsertObservationBuilder(SosStation station, SosSensor sensor, 
			Phenomenon phenomenon, ObservationCollection observationCollection, 
			IdCreator idCreator, Double depth){
		this.station = station;
		this.sensor = sensor;
		this.phenomenon = phenomenon;
		this.observationCollection = observationCollection;
		this.idCreator = idCreator;
		this.depth = depth;
	}
	
	// -------------------------------------------------------------------------
	// Override Members
	// -------------------------------------------------------------------------
	
	/**
	 * Create InsertObservation XML
	 * example:
	 * <InsertObservation service="SOS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosInsert.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/extensions/observationSpecialization_override.xsd">
	 * 	<AssignedSensorId>urn:ioos:sensor:aoos:pilotrock:airtemp</AssignedSensorId>
	 * 	<om:Observation>
	 * 		<om:samplingTime>
	 * 			<gml:TimePeriod xsi:type="gml:TimePeriodType">
	 * 				<gml:beginPosition>2012-04-17T12:02:05-0000</gml:beginPosition>
	 * 				<gml:endPosition>2012-04-17T20:02:05-0000</gml:endPosition>
	 * 			</gml:TimePeriod>
	 * 		</om:samplingTime>
	 * 		<om:procedure xlink:href="urn:ogc:object:feature:Sensor:3234"/>
	 *      <om:observedProperty>
   	 *			<swe:CompositePhenomenon gml:id="cpid0" dimension="1">
     *				<gml:name>resultComponents</gml:name>
     *				<swe:component xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
     *				<swe:component xlink:href="urn:x-ogc:def:phenomenon:IOOS:0.0.1:air_temperature" />
     * 			</swe:CompositePhenomenon>
  	 *		</om:observedProperty>
	 * 		<om:featureOfInterest>
	 * 			<gml:FeatureCollection>
	 * 				<gml:featureMember>
	 * 					<sa:SamplingPoint gml:id="foi_3234">
	 * 						<gml:name>The sampling point at station: Anchorage Hillside - AOOS</gml:name>
	 * 						<sa:sampledFeature xlink:href=""/>
	 * 						<sa:position>
	 * 							<gml:Point>
	 * 								<gml:pos srsName="urn:ogc:def:crs:EPSG::4326">-143.0 63.0</gml:pos>
	 * 							</gml:Point>
	 * 						</sa:position>
	 * 					</sa:SamplingPoint>
	 * 				</gml:featureMember>
	 * 			</gml:FeatureCollection>
	 * 		</om:featureOfInterest>
	 * 		<om:result>
	 * 			<swe:DataArray>
	 * 				<swe:elementCount>
	 * 					<swe:Count>
	 * 						<swe:value>3</swe:value>
	 * 					</swe:Count>
	 * 				</swe:elementCount>
	 * 				<swe:elementType name="Components">
	 * 					<swe:DataRecord>
	 * 						<swe:field name="feature">
	 * 							<swe:Text definition="http://www.opengis.net/def/property/OGC/0/FeatureOfInterest"/>
	 * 						</swe:field>
	 * 						<swe:field name="Time">
	 * 							<swe:Time definition="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"/>
	 * 						</swe:field>
	 * 						<swe:field name="Air Temperature">
	 * 							<swe:Quantity definition="urn:x-ogc:def:phenomenon:IOOS:0.0.1:air_temperature">
	 * 								<swe:uom code="C"/>
	 * 							</swe:Quantity>
	 * 						</swe:field>
	 * 					</swe:DataRecord>
	 * 				</swe:elementType>
	 * 				<swe:encoding>
	 * 					<swe:TextBlock blockSeparator=";" decimalSeparator="." tokenSeparator=","/>
	 * 				</swe:encoding>
	 * 				<swe:values>
	 * 					foi_3234,2012-04-17T20:02:05-0000,10.0;foi_3234,2012-04-17T16:02:05-0000,11.0;foi_3234,2012-04-17T12:02:05-0000,12.0;
	 * 				</swe:values>
	 * 			</swe:DataArray>
	 * 		</om:result>
	 * 	</om:Observation>
	 * </InsertObservation>
	 */
    @Override
	public String build() {
		try{
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		
		Document doc = docBuilder.newDocument();
		Element insertObservation = doc.createElement("InsertObservation");
		insertObservation.setAttribute("xmlns", "http://www.opengis.net/sos/1.0");
		insertObservation.setAttribute("xmlns:ows", "http://www.opengis.net/ows/1.1");
		insertObservation.setAttribute("xmlns:ogc", "http://www.opengis.net/ogc");
		insertObservation.setAttribute("xmlns:om", "http://www.opengis.net/om/1.0");
		insertObservation.setAttribute("xmlns:sos", "http://www.opengis.net/sos/1.0");
		insertObservation.setAttribute("xmlns:sa", "http://www.opengis.net/sampling/1.0");
		insertObservation.setAttribute("xmlns:gml", "http://www.opengis.net/gml");
		insertObservation.setAttribute("xmlns:swe", "http://www.opengis.net/swe/1.0.1");
		insertObservation.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
		insertObservation.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
		insertObservation.setAttribute("xsi:schemaLocation", "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosInsert.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/extensions/observationSpecialization_override.xsd");
		insertObservation.setAttribute("service", "SOS");
		insertObservation.setAttribute("version", "1.0.0");
		doc.appendChild(insertObservation);
		
		String procedureId = idCreator.createSensorId(station, sensor);
		
		Element assignedSensorId = doc.createElement("AssignedSensorId");
		assignedSensorId.appendChild(doc.createTextNode(procedureId));
		insertObservation.appendChild(assignedSensorId);
		
		Element observation = doc.createElement("om:Observation");
		observation.appendChild(getSamplingTime(doc));
		insertObservation.appendChild(observation);
		
		Element procedure = doc.createElement("om:procedure");
		procedure.setAttribute("xlink:href", procedureId);
		observation.appendChild(procedure);
		
		observation.appendChild(createObservedProperty(doc));
		
		observation.appendChild(createFeatureOfInterest(doc));
		
		observation.appendChild(createResult(doc, station));
		
		String xmlString = getString(doc);
                
        return xmlString;<commit_msg>attempting to fix feature-of-interest insertion error<commit_after>package com.axiomalaska.sos.xmlbuilder;

import java.util.Calendar;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.axiomalaska.phenomena.Phenomenon;
import com.axiomalaska.sos.data.SosSensor;
import com.axiomalaska.sos.data.SosStation;
import com.axiomalaska.sos.data.ObservationCollection;
import com.axiomalaska.sos.tools.IdCreator;

/**
 * Builds a SOS InsertObservation XML String with the ObservationCollection and station
 * 
 * @author <NAME>
 */
public class InsertObservationBuilder extends SosXmlBuilder {

	// -------------------------------------------------------------------------
	// Private Data
	// -------------------------------------------------------------------------
	
	private SosStation station;
	private SosSensor sensor;
	private ObservationCollection observationCollection;
	private IdCreator idCreator;
	private Phenomenon phenomenon;
	private Double depth;
	
	// -------------------------------------------------------------------------
	// Constructor
	// -------------------------------------------------------------------------
	
	public InsertObservationBuilder(SosStation station, SosSensor sensor, 
			Phenomenon phenomenon, ObservationCollection observationCollection, 
			IdCreator idCreator, Double depth){
		this.station = station;
		this.sensor = sensor;
		this.phenomenon = phenomenon;
		this.observationCollection = observationCollection;
		this.idCreator = idCreator;
		this.depth = depth;
	}
	
	// -------------------------------------------------------------------------
	// Override Members
	// -------------------------------------------------------------------------
	
	/**
	 * Create InsertObservation XML
	 * example:
	 * <InsertObservation service="SOS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosInsert.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/extensions/observationSpecialization_override.xsd">
	 * 	<AssignedSensorId>urn:ioos:sensor:aoos:pilotrock:airtemp</AssignedSensorId>
	 * 	<om:Observation>
	 * 		<om:samplingTime>
	 * 			<gml:TimePeriod xsi:type="gml:TimePeriodType">
	 * 				<gml:beginPosition>2012-04-17T12:02:05-0000</gml:beginPosition>
	 * 				<gml:endPosition>2012-04-17T20:02:05-0000</gml:endPosition>
	 * 			</gml:TimePeriod>
	 * 		</om:samplingTime>
	 * 		<om:procedure xlink:href="urn:ogc:object:feature:Sensor:3234"/>
	 *      <om:observedProperty>
   	 *			<swe:CompositePhenomenon gml:id="cpid0" dimension="1">
     *				<gml:name>resultComponents</gml:name>
     *				<swe:component xlink:href="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian" />
     *				<swe:component xlink:href="urn:x-ogc:def:phenomenon:IOOS:0.0.1:air_temperature" />
     * 			</swe:CompositePhenomenon>
  	 *		</om:observedProperty>
	 * 		<om:featureOfInterest>
	 * 			<gml:FeatureCollection>
	 * 				<gml:featureMember>
	 * 					<sa:SamplingPoint gml:id="foi_3234">
	 * 						<gml:name>The sampling point at station: Anchorage Hillside - AOOS</gml:name>
	 * 						<sa:sampledFeature xlink:href=""/>
	 * 						<sa:position>
	 * 							<gml:Point>
	 * 								<gml:pos srsName="urn:ogc:def:crs:EPSG::4326">-143.0 63.0</gml:pos>
	 * 							</gml:Point>
	 * 						</sa:position>
	 * 					</sa:SamplingPoint>
	 * 				</gml:featureMember>
	 * 			</gml:FeatureCollection>
	 * 		</om:featureOfInterest>
	 * 		<om:result>
	 * 			<swe:DataArray>
	 * 				<swe:elementCount>
	 * 					<swe:Count>
	 * 						<swe:value>3</swe:value>
	 * 					</swe:Count>
	 * 				</swe:elementCount>
	 * 				<swe:elementType name="Components">
	 * 					<swe:DataRecord>
	 * 						<swe:field name="feature">
	 * 							<swe:Text definition="http://www.opengis.net/def/property/OGC/0/FeatureOfInterest"/>
	 * 						</swe:field>
	 * 						<swe:field name="Time">
	 * 							<swe:Time definition="http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"/>
	 * 						</swe:field>
	 * 						<swe:field name="Air Temperature">
	 * 							<swe:Quantity definition="urn:x-ogc:def:phenomenon:IOOS:0.0.1:air_temperature">
	 * 								<swe:uom code="C"/>
	 * 							</swe:Quantity>
	 * 						</swe:field>
	 * 					</swe:DataRecord>
	 * 				</swe:elementType>
	 * 				<swe:encoding>
	 * 					<swe:TextBlock blockSeparator=";" decimalSeparator="." tokenSeparator=","/>
	 * 				</swe:encoding>
	 * 				<swe:values>
	 * 					foi_3234,2012-04-17T20:02:05-0000,10.0;foi_3234,2012-04-17T16:02:05-0000,11.0;foi_3234,2012-04-17T12:02:05-0000,12.0;
	 * 				</swe:values>
	 * 			</swe:DataArray>
	 * 		</om:result>
	 * 	</om:Observation>
	 * </InsertObservation>
	 */
    @Override
	public String build() {
		try{
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		
		Document doc = docBuilder.newDocument();
		Element insertObservation = doc.createElement("InsertObservation");
		insertObservation.setAttribute("xmlns", "http://www.opengis.net/sos/1.0");
		insertObservation.setAttribute("xmlns:ows", "http://www.opengis.net/ows/1.1");
		insertObservation.setAttribute("xmlns:ogc", "http://www.opengis.net/ogc");
		insertObservation.setAttribute("xmlns:om", "http://www.opengis.net/om/1.0");
		insertObservation.setAttribute("xmlns:sos", "http://www.opengis.net/sos/1.0");
		insertObservation.setAttribute("xmlns:sa", "http://www.opengis.net/sampling/1.0");
		insertObservation.setAttribute("xmlns:gml", "http://www.opengis.net/gml");
		insertObservation.setAttribute("xmlns:swe", "http://www.opengis.net/swe/1.0.1");
		insertObservation.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
		insertObservation.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
		insertObservation.setAttribute("xsi:schemaLocation", "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosInsert.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/extensions/observationSpecialization_override.xsd");
		insertObservation.setAttribute("service", "SOS");
		insertObservation.setAttribute("version", "1.0.0");
		doc.appendChild(insertObservation);
		
		String procedureId = idCreator.createSensorId(station, sensor);
		
		Element assignedSensorId = doc.createElement("AssignedSensorId");
		assignedSensorId.appendChild(doc.createTextNode(procedureId));
		insertObservation.appendChild(assignedSensorId);
		
		Element observation = doc.createElement("om:Observation");
		observation.appendChild(getSamplingTime(doc));
		insertObservation.appendChild(observation);
		
		Element procedure = doc.createElement("om:procedure");
		procedure.setAttribute("xlink:href", procedureId);
		observation.appendChild(procedure);
		
		observation.appendChild(createObservedProperty(doc));
		
		observation.appendChild(createFeatureOfInterest(doc));
		
		observation.appendChild(createResult(doc, station));
		
		String xmlString = getString(doc);
                
                System.out.println(xmlString);
                
        return xmlString;
{'fraction_non_alphanumeric': 0.20588636984430483, 'fraction_numerical': 0.02895383774924884, 'mean_word_length': 3.034435261707989, 'pattern_counts': {'":': 0, '<': 145, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 38, 'xml': 31}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1375469', 'n_tokens_mistral': 5825, 'n_tokens_neox': 4952, 'n_words': 555}