Ejemplo n.º 1
0
func QueryObservations(c gossamer.Client) {
	o, err := c.QueryObservations().All()
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Query all Observations returned records # ", len(o))
}
Ejemplo n.º 2
0
func InsertDatastream(c gossamer.Client) {
	e := gossamer.NewDatastreamEntity()
	e.PhenomenonTime = gossamer.NewTimePeriod(time.Now(), time.Now())
	e.ResultTime = gossamer.NewTimePeriod(time.Now(), time.Now())
	e.Description = "XXX"
	e.ObservationType = gossamer.DATASTREAM_OBSTYPE_OBSERVATION
	e.UnitOfMeasurement = "XXX"

	thing := gossamer.NewThingEntity()
	thing.Id = "ABC123"
	e.Thing = thing

	sensor := gossamer.NewSensorEntity()
	sensor.Id = "DEF312"
	e.Sensor = sensor

	obsProp := gossamer.NewObservedPropertyEntity()
	obsProp.Id = "GHI987"
	e.ObservedProperty = obsProp

	err := c.InsertDatastream(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Datastream")
}
Ejemplo n.º 3
0
func InsertThing(c gossamer.Client) {
	e := gossamer.NewThingEntity()
	e.Description = "XXXXX"

	err := c.InsertThing(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Thing")
}
Ejemplo n.º 4
0
func InsertSensor(c gossamer.Client) {
	e := gossamer.NewSensorEntity()
	e.Description = "XXXXXX"
	e.EncodingType = gossamer.SENSOR_ENCTYPE_SENSORML
	e.Metadata = "XXXXX"

	err := c.InsertSensor(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Sensor")
}
Ejemplo n.º 5
0
func InsertObservedProperty(c gossamer.Client) {
	e := gossamer.NewObservedPropertyEntity()
	e.Name = "XXXX"
	e.Description = "XXXXXX"
	e.Definition = "XXXXX"

	err := c.InsertObservedProperty(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New ObservedProperty")
}
Ejemplo n.º 6
0
func InsertFeaturesOfInterest(c gossamer.Client) {
	e := gossamer.NewFeatureOfInterestEntity()
	e.Description = "XXXX"
	e.EncodingType = gossamer.LOCATION_ENCTYPE_GEOJSON
	e.Feature = "Feature ABC 1 2 3"

	err := c.InsertFeaturesOfInterest(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Feature of Interest")
}
Ejemplo n.º 7
0
func InsertLocation(c gossamer.Client) {
	e := gossamer.NewLocationEntity()
	e.Description = "XXXXX"
	e.EncodingType = gossamer.LOCATION_ENCTYPE_GEOJSON
	e.Location = "XOXOXO"

	err := c.InsertLocation(e)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Location")
}
Ejemplo n.º 8
0
func FindSensors(c gossamer.Client) {
	ol, e := c.FindSensors()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetSensor(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Got Sensor Entity ", o.GetId())
		}
	}
}
Ejemplo n.º 9
0
func InsertObservation(c gossamer.Client) {
	obs := &gossamer.ObservationEntity{}
	obs.PhenomenonTime = gossamer.NewTimePeriod(time.Now(), time.Now())
	obs.Result = "123"
	obs.ResultTime = gossamer.NewTimeInstant(time.Now())
	ds := &gossamer.DatastreamEntity{}
	ds.Id = "Datastream-1"
	obs.Datastream = ds

	err := c.InsertObservation(obs)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Inserted New Observation")
}
Ejemplo n.º 10
0
func FindDatastreams(c gossamer.Client) {
	ol, e := c.FindDatastreams()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetDatastream(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Got Datastream Entity ", o.GetId())
		}
	}
}
Ejemplo n.º 11
0
func FindObservedProperties(c gossamer.Client) {
	ol, e := c.FindObservedProperties()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetObservedProperty(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Got Observed Property Entity ", o.GetId())
		}
	}
}
Ejemplo n.º 12
0
func FindLocations(c gossamer.Client) {
	ol, e := c.FindLocations()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetLocation(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Got Location Entity ", o.GetId())
		}
	}
}
Ejemplo n.º 13
0
func FindFeaturesOfInterest(c gossamer.Client) {
	ol, e := c.FindFeaturesOfInterest()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetFeaturesOfInterest(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			log.Println("Got FeaturesofInterest Entity ", o.GetId())
		}
	}
}
Ejemplo n.º 14
0
func PatchObservations(c gossamer.Client) {
	l, err := c.QueryObservations().Top(1).All()
	if err != nil {
		log.Fatal(err)
	}

	var o gossamer.Observation
	if len(l) > 0 {
		o = l[0].(gossamer.Observation)

		n := gossamer.CloneObservationEntity(o)
		n.ResultQuality = "Value was changed"
		n.ResultTime = gossamer.NewTimeInstant(time.Now())

		c.PatchObservation(n)
	}
}
Ejemplo n.º 15
0
func UpdateSensors(c gossamer.Client) {
	l, err := c.QuerySensors().Top(1).All()
	if err != nil {
		log.Fatal(err)
	}

	var o gossamer.Sensor
	if len(l) > 0 {
		o = l[0].(gossamer.Sensor)

		n := gossamer.CloneSensorEntity(o)
		n.Description = "Updated description"

		err = c.UpdateSensor(n)
		if err != nil {
			log.Fatal(err)
		}
	}
}
Ejemplo n.º 16
0
func DeleteSensors(c gossamer.Client) {
	ol, e := c.FindSensors()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetSensor(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			// Delete Observation
			e := c.DeleteSensor(o.GetId())
			if e != nil {
				log.Fatal(err)
			} else {
				log.Println("Deleted Sensor ", o.GetId())
			}
		}
	}
}
Ejemplo n.º 17
0
func DeleteObservedProperties(c gossamer.Client) {
	ol, e := c.FindObservedProperties()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetObservedProperty(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			// Delete Observation
			e := c.DeleteObservedProperty(o.GetId())
			if e != nil {
				log.Fatal(err)
			} else {
				log.Println("Deleted ObservedProperty ", o.GetId())
			}
		}
	}
}
Ejemplo n.º 18
0
func DeleteFeaturesOfInterest(c gossamer.Client) {
	ol, e := c.FindFeaturesOfInterest()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetFeaturesOfInterest(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			// Delete Observation
			e := c.DeleteFeaturesOfInterest(o.GetId())
			if e != nil {
				log.Fatal(err)
			} else {
				log.Println("Deleted FeatureOfInterest ", o.GetId())
			}
		}
	}
}
Ejemplo n.º 19
0
func DeleteDatastreams(c gossamer.Client) {
	ol, e := c.FindDatastreams()
	if e != nil {
		log.Fatal(e)
	}

	for _, v := range ol {
		o, err := c.GetDatastream(v.GetId())
		if err != nil {
			log.Fatal(err)
		} else {
			// Delete Observation
			e := c.DeleteDatastream(o.GetId())
			if e != nil {
				log.Fatal(err)
			} else {
				log.Println("Deleted Datastream ", o.GetId())
			}
		}
	}
}